hi all

I'd like to have certain fields in several models, like alias field in
this:

class Person(models.Model):
    name = models.CharField(max_length=255)
    alias = models.ForeignKey('self', blank=True, null=True)

class Place(models.Model):
    street = models.CharField(max_length=255)
    alias = models.ForeignKey('self', blank=True, null=True)

to repeat alias in every model is not DRY. also I'd like to have
Manager returning for example all aliases for all of such models and
model methods to manipulate with aliases. so it should be common for
several models. I see a way to achieve this is to inherit
models.Model, add necessary fields/managers/methods to it and the
inherit my models from it, like:

class MyModel(models.Model):
    alias = models.ForeignKey('self', blank=True, null=True)
    manager = [my alias manager here]
    def getAlias:
          [whatever I need]

class Person(MyModel):
    name = models.CharField(max_length=255)

class Place(MyModel):
    street = models.CharField(max_length=255)

my questions are:
1. is it the right way to go?
2. are there any pitfalls?

thanks
Maxim
http://zeliboba.by.ru


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

Reply via email to