Plain ol' Python multiple inheritance should work. Just define the
fields you want in some class:
{{{
class PersonMixin(object):
    first = models.CharField(max_length=16)
    last = models.CharField(max_length=16)

class Person(models.Model, PersonMixin):
    pass

class Person2(models.Model, PersonMixin):
    pass
}}}

On Apr 30, 10:58 pm, Ramashish Baranwal <ramashish.li...@gmail.com>
wrote:
> > > I want to create several tables with same schema. This is to partition
> > > the data into different tables. Apart from having model classes with
> > > same definition, is there another way to do it?
>
> > > Here is a trivial example that duplicates the class definition-
>
> > > class Person(models.Model):
> > >    first = models.CharField(max_length=16)
> > >    last = models.CharField(max_length=16)
>
> > > class Person2(models.Model):
> > >    first = models.CharField(max_length=16)
> > >    last = models.CharField(max_length=16)
>
> > > Apart from the code duplication, the above doesn't capture the intent
> > > that the two models represent tables with same schema. I'm looking for
> > > something like-
>
> > > class Person2(Person):
> > >    pass
>
> > > The above however doesn't work.
> > > Any idea?
>
> > > Thanks,
> > > Ram
>
> > I'd do it with one class that has all the common fields that is an abstract
> > class(check the docs for this).  And then just 2 classes that subclass it.
> > This should do just what you want.
>
> Hi Alex,
>
> Thanks for the quick reply. Abstract class fits the need perfectly.
> However, I am using Django 0.96 where abstract class functionality is
> not available. I can't upgrade  Django currently.
> Any other way?
>
> -Ram
--~--~---------~--~----~------------~-------~--~----~
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