According to sets theory you should not even care about order of
columns, the same as happens with the elements of a Python dict.

You can always tweak the generated sql for aesthetics...

El mié, 21-12-2005 a las 01:03 +0000, braver escribió:
> Is there a way to do single table inheritance in django?  E.g., I have
> this part of a classical CD model:
> 
> # order is preserved here,
> # but changes for derived classes => so we invert it for them!
> 
> class Person(meta.Model):
>     middle_name = meta.TextField(null=True)
>     last_name   = meta.TextField()
>     first_name  = meta.TextField()
> 
> class Composer(Person):
>     pass
> 
> class Conductor(Person):
>     pass
> 
> class Soloist(Person):
>     pass
> 
> Here's the SQL generated by django:
> 
> CREATE TABLE "cd_persons" (
>     "id" integer NOT NULL PRIMARY KEY,
>     "middle_name" text NULL,
>     "last_name" text NOT NULL,
>     "first_name" text NOT NULL
> );
> 
> CREATE TABLE "cd_composers" (
>     "id" integer NOT NULL PRIMARY KEY,
>     "first_name" text NOT NULL,
>     "last_name" text NOT NULL,
>     "middle_name" text NULL
> ...
> 
> -- notice that the order of columns for Person corresponds to
> cd_persons, but for the derived classes it's backwards!  Thus, I
> inverted it in Person -- which is, in fact, abstract in C++ sense, I'm
> only going to use Composer/Conductor/Soloist.  The SQL generator
> appears broken for the order of the derived classes, or I'm not
> supposed to do such things in a model?
> 
> Rails has "single table inheritance" in the sense you can put all
> attributes into one table, and superimpose all classes on it, with an
> extra "type" column as the discriminant/class tag.  Any such thing in
> django?
> 
-- 
Marcos Sánchez Provencio <[EMAIL PROTECTED]>

Reply via email to