2009-09-14 59 views
2

我的模型是这样的.filter跨表中的抽象模型类 - Django的

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(..) 

我想所有的酒吧,巴兹(和其他FooSubclasses),其中有user__username =“你好”

我做Foo.objects.filter(user__username = 'hello')。这给我一个错误'Options' object has no attribute '_join_cache'

我该怎么做?

+0

本页面中的部分信息可能会对您有所帮助 http://stackoverflow.com/questions/7884359/foreignkey-to-abstract-class-generic-relations – 2012-10-08 12:21:37

回答

4

抽象模型不在数据库中作为表存在,也无法查询。您可能必须分别在Bar和Baz模型上编写两个查询,然后合并结果。

为了组织目的,您可以将它包装到Foo类中的方法中。