Saturday, April 16, 2011

Using composition in Django

Hello!
I have two class, Person and employee, i need make a composition for
this (Prefer composition over inheritance):

class Person(models.Model):
name = models.CharField(max_length=50)
date_inclusion = models.DateField()
# others fields

class Employee(models.Model):
person = models.OneToOneField(Person, primary_key=True)
address = models.OneToOneField(Address, primary_key=True)


The SQL generate is:


BEGIN;
CREATE TABLE "person_person" (
"id" serial NOT NULL PRIMARY KEY,
"name" varchar(50) NOT NULL,
"date_inclusion" date NOT NULL,
)
;
CREATE TABLE "employee_employee" (
"person_id" integer NOT NULL PRIMARY KEY,
"address_id" integer NOT NULL PRIMARY KEY,
)
;


This is correct? Should generate the id of the employee?
Proxy models could be used for this case?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate