Hi Guevara,

Proxy models only inherit python logic, they are what you expect when
you subclass a superclass; I dont think thats what you want in this
case.

I think you actually do want multi-table inheritence, im not too well
educated in "design patterns" but i think thats what you mean by
composition. However, allthough Python itselfs supports
multiple-inheretence, im not sure if that works with more then two
Django models.

Subclassing a Django model implies a OneToOne relationship which is
automaticly generated. An instance of employee should then contain
fields from both Person and Adress on the python layer, and contain
only the foreign keys on the database layer. Again i'm not sure if
this works with 3 models involved (Address, Person and Employee). Take
a look at 
http://docs.djangoproject.com/en/1.3/topics/db/models/#multi-table-inheritance

This is what i mean:

class Person(models.Model):
     first_name ...
     last_name ...

class Adress(models.Model):
     street ...
     city ...

class Employee(Person, Adress):
    pass

Regards, Yuka

On Sat, Apr 16, 2011 at 10:35 PM, Guevara <eguevara2...@gmail.com> wrote:
> 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+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to