On Fri, May 15, 2009 at 10:10 AM, Alex Gaynor <alex.gay...@gmail.com> wrote:
> > > On Fri, May 15, 2009 at 12:08 PM, Rusty Greer <gr...@greer.org> wrote: > >> >> >> On Fri, May 15, 2009 at 9:57 AM, George Song <geo...@damacy.net> wrote: >> >>> >>> On 5/15/2009 8:18 AM, Rusty Greer wrote: >>> > >>> > >>> > I have something like this: >>> > >>> > class Class1(models.Model): >>> > // lots of fields here >>> > >>> > class AbstractThing(models.Model): >>> > // lots of fields here >>> > class1field = model.ForeignKey(Class1) >>> > class Meta: >>> > abstract = True >>> > >>> > class ThingType1(AbstractThing): >>> > // lots of fields here >>> > >>> > class ThingType2(AbstractThing): >>> > // lots of fields here >>> > >>> > >>> > in my template, i want to be able to do something like: >>> > class1.abstractthing_set.all >>> > >>> > but that doesn't seem to work, i seem to have to do: >>> > class1.thingtype1_set.all and class1.thingtype2_set.all >>> > >>> > does this make sense? am i missing something? >>> > >>> > any help would be appreciated. >>> >>> The pattern you describe should work fine. What exactly isn't working? >>> >>> -- >>> George >>> >>> >> from within the template, class1.abstractthing_set.all returns nothing, >> class1.thingtype1_set.all returns exactly what is expected >> >> from python code, class1.abstractthing_set.all gives me an AttributeError >> >> 'class1' object has no attribute 'abstractthing_set' >> >> >> class1.thingtype1_set.all returns exactly what is expected >> >> i was hoping that the abstractthing_set would return all of the objects of >> both thingtype1 and thingtype2 >> >> >> >> > An abstract model doesn't exist in the database, therefore trying to get > objects for it doesn't make sense, you either need to use concrete > inheritance or manually query the individual models. > > Alex > OK. I guess that makes sense. I was thinking more from an object point of view. If I use a concrete base class instead of an abstract one, there will be multiple tables combined to represent the data. So each fetch will be a join of some number of tables. Because the tables are somewhat similar, would it be more efficient to have 1 table with some unused fields or multiple tables and having to do a join? Rusty --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---