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)
精彩评论