List Info

Thread: Inheritance




Inheritance
user name
2007-12-24 06:21:11
Hi. Forgive my poor English.

I have a lot of models for classifications. All of them have
similar
attributes. When I try to use inheritance in the models
design, the
admin interface doesn't work with ForeignKey fields.

Example:

class BasicModel(models.Model):
    name=models.CharField(maxlength=30)
    def __str__(self):
        return self.name

class Reference(BasicModel):
    class Admin:
        pass

class Data(BasicModel):
    ref = models.ForeingKey(Reference)
    class Admin:
        pass

Here, the ref field doesn't show all of their records in the
Admin Add
Data form.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Inheritance
user name
2007-12-24 08:35:41
> I have a lot of models for classifications. All of them
have similar
> attributes. When I try to use inheritance in the models
design, the
> admin interface doesn't work with ForeignKey fields.
>
> Example:
>
> class BasicModel(models.Model):
>     name=models.CharField(maxlength=30)
>     def __str__(self):
>         return self.name
>
> class Reference(BasicModel):
>     class Admin:
>         pass
>
> class Data(BasicModel):
>     ref = models.ForeingKey(Reference)
>     class Admin:
>         pass
>
> Here, the ref field doesn't show all of their records
in the Admin Add
> Data form.

You will likely run into all kinds of problems.  Model
Inheritance is
currently not supported in Django.  There has been
discussions and
proposals on the topic so I suspect that it will be
available at some
point.  See here:

h
ttp://code.djangoproject.com/wiki/ModelInheritance

Michael Trier
blog.michaeltrier.com

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


Re: Inheritance
country flaguser name
United States
2007-12-27 12:30:47
>> I have a lot of models for classifications. All of
them have similar
>> attributes. When I try to use inheritance in the
models design, the
>> admin interface doesn't work with ForeignKey
fields.
>>
>> Example:
>>
>> class BasicModel(models.Model):
>>     name=models.CharField(maxlength=30)
>>     def __str__(self):
>>         return self.name
>>
>> class Reference(BasicModel):
>>     class Admin:
>>         pass
>>
>> class Data(BasicModel):
>>     ref = models.ForeingKey(Reference)
>>     class Admin:
>>         pass
>>
>> Here, the ref field doesn't show all of their
records in the Admin Add
>> Data form.
>
> You will likely run into all kinds of problems.  Model
Inheritance is
> currently not supported in Django.  There has been
discussions and
> proposals on the topic so I suspect that it will be
available at some
> point.  See here:
>
> h
ttp://code.djangoproject.com/wiki/ModelInheritance

Also you may try to use multiple inheritance, which has
worked for me for 
extending models, i.e.

class YourModel(YourOtherModel,models.Model):

Not sure if it will work for your purpose, but give it a
try!

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


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )