Valentin Golev
Valentin Golev

Reputation: 10095

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 JournalistRequests 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?

Upvotes: 0

Views: 89

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599628

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

UserRequest.objects.filter(journalistrequest=None)

Upvotes: 2

Related Questions