开发者

django models: how to select only objects which aren't belong to the inherited class?

I have two models in my Django 1.1.1 application:

class UserRequest(models.Model):
   # blah blah

class JournalistRequest(UserRequest):
    # blah blah

So, JournalistRequest is a special type of UserRequest, and all Journal开发者_如何学GoistRequests are still common UserRequests with special fields.

JournalistRequest.objects.all() returns all JournalistRequests. UserRequest.objects.all() returns all UserRequests, both Journalists and not. How to select all UserRequests which are not JournalistRequests?


Assuming you are using multi-table inheritance, the following should work:

UserRequest.objects.filter(journalistrequest=None)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜