Re: Model Inheritance question
LeeRisq wrote: > If I am looking to use an abstract base class with multiple models, > which is assigned the primary key id? The child or the parent? Abstract classes don't get database tables at all, so only the child will have the key. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Model Inheritance question
If I am looking to use an abstract base class with multiple models, which is assigned the primary key id? The child or the parent? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Model inheritance question
see also this: http://www.djangosnippets.org/snippets/1031/ for a tumblelog I have been actually fetching queries for each item type, concatenating them as lists, then sorting by date. that's much simpler since its usually mostly display. I mostly use model inheritance in situations where I need to search shared fields (contacts, companies, location). On Sun, Nov 2, 2008 at 1:52 AM, void <[EMAIL PROTECTED]> wrote: > > Can someone point to the correct way to do this? > > Suppose i'm working in a tumblelog, it's basically , 4 o 5 tipes of > "post item" that share some cmmon information. > > So the first approach i would go is: > > cllass Post(models.Model): > here goes common metada of all things that can be "posted" like > taggin , dates, etc > > class TextPost(Post) > This model inherits all the metadata of the "normal" posteable > objects and add some of it's own like > > text = TexField() > > also we can provide a ImagePost(Post) with the same characteristics as > textpost, > > The caveat folllow: > > Inheritance gives me a reference in the "child" model to the pk of the > parent, that's ok. > But i have no way of iterating to Posts elements and instantiating > them osr seeing their attrs without knowing the correct nadme. > > Is any correct way to do this? will i have to hack django (or add a > field) that backreferences the reference? > > The idea is traverse only the Posts objects instead o N tables (1 for > each kinkd of post) > > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Model inheritance question
On Sun, Nov 2, 2008 at 4:52 AM, void <[EMAIL PROTECTED]> wrote: > > Can someone point to the correct way to do this? > > Suppose i'm working in a tumblelog, it's basically , 4 o 5 tipes of > "post item" that share some cmmon information. > > So the first approach i would go is: > > cllass Post(models.Model): > here goes common metada of all things that can be "posted" like > taggin , dates, etc > > class TextPost(Post) > This model inherits all the metadata of the "normal" posteable > objects and add some of it's own like > > text = TexField() > > also we can provide a ImagePost(Post) with the same characteristics as > textpost, > > The caveat folllow: > > Inheritance gives me a reference in the "child" model to the pk of the > parent, that's ok. > But i have no way of iterating to Posts elements and instantiating > them osr seeing their attrs without knowing the correct nadme. > > Is any correct way to do this? will i have to hack django (or add a > field) that backreferences the reference? > > The idea is traverse only the Posts objects instead o N tables (1 for > each kinkd of post) > See this thread for some ideas: http://groups.google.com/group/django-users/browse_thread/thread/f4241bc16455f92d/dcd2bfcc91d99cc9 -- Ramiro Morales --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Model inheritance question
Can someone point to the correct way to do this? Suppose i'm working in a tumblelog, it's basically , 4 o 5 tipes of "post item" that share some cmmon information. So the first approach i would go is: cllass Post(models.Model): here goes common metada of all things that can be "posted" like taggin , dates, etc class TextPost(Post) This model inherits all the metadata of the "normal" posteable objects and add some of it's own like text = TexField() also we can provide a ImagePost(Post) with the same characteristics as textpost, The caveat folllow: Inheritance gives me a reference in the "child" model to the pk of the parent, that's ok. But i have no way of iterating to Posts elements and instantiating them osr seeing their attrs without knowing the correct nadme. Is any correct way to do this? will i have to hack django (or add a field) that backreferences the reference? The idea is traverse only the Posts objects instead o N tables (1 for each kinkd of post) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Poor man's model inheritance question.
Hi, I am using OneToOneField to simulate model inheritance. I have all the shared fields in a base model, and then for every specific case I have a derived model that has a OneToOneField to that base model. That was all working fine. Recently I was trying to encapsulate some of the functionality that is in all the derived models into a base class. So I have something similar to the following: --- class Base(models.Model): common_field = models.CharField() class CommonFunc(models.Model): def save(self): do_common_thing() super(CommonFunc,self).save() class DerivedModel(CommonFunc): base = models.OneToOneField(Base) specific_field = models.CharField() --- The problem I am having is that for some reason it is not detecting that the one-to-one field is a primary key and when I syncdb it gives me an error that DerivedModel has two primary keys since django adds the implicit id field. Is this a bug? Is there a better way for me to achieve this? Or should I just wait patiently until model inheritance is implemented? -- Thanks, Medhat --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---