views:

165

answers:

1

My model is like this

class Foo(models.Model):
    user = models.ForeignKey(User)

    class Meta:
        abstract = True

class Bar(Foo):
    bar_thing = models.CharField(..)

class Baz(Foo):
    baz_thing = models.CharField(..)

I want to get all bar, baz (And other FooSubclasses) which have user__username = 'hello'

i do Foo.objects.filter(user__username = 'hello'). This gives me an error 'Options' object has no attribute '_join_cache'

How can I do this?

+3  A: 

The abstract model does not exist as a table in your database, and it can't be queried. You will probably have to write two queries separately on the Bar and Baz models, and then merge the results.

You could wrap this into a method in your Foo class for organizational purposes.

Fragsworth