2009-09-14 1 views
2

내 모델은 내가 모든 줄을 얻으려면이.filter - 장고

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 = '안녕하세요'이있는 나는 do 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 –

답변

4

추상 모델이 데이터베이스의 테이블로 존재하지 않으며 쿼리 할 수 ​​없습니다. Bar와 Baz 모델에 별도로 두 개의 쿼리를 작성한 다음 결과를 병합해야 할 것입니다.

조직 목적으로 Foo 클래스의 메소드에이를 래핑 할 수 있습니다.