.filter via tables in abstract model class - Django

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 bars, baz (and other FooSubclasses) that have user__username = 'hello'

i do Foo.objects.filter(user__username = 'hello')

. This is giving me error'Options' object has no attribute '_join_cache'

How can i do this?

+2


source to share


1 answer


The abstract model does not exist as a table in your database and cannot be queried. You may have to write two queries separately on the Bar and Baz models and then combine the results.



You can wrap this as a method in your Foo class for organizational purposes.

+4


source







All Articles