I m working on a custom Django Admin FilterSpec (covered already on SO #991926). My FilterSpec is a replacement for the default filter on ForeignKey(User), and basically replaces the list of all users with three only choices, all, mine, and others.
For example, if I applied the custom filterspec to the field created_by
it would add an admin filter with All, Created by Me, and Created by Others. Everything works except the negative filter, Created by Others.
I ve been attempting to achieve this by appending __not
to the query as so:
def choices(self, cl):
yield {
selected : self.lookup_val == self.user.pk,
query_string : cl.get_query_string({ %s__not % self.field.name: self.user.pk}),
display : capfirst( %s Others % self.field.verbose_name)
}
It doesn t seem that Django supports filtering in the negative like this. I ve also experimented with having it do a __gte
and __lte
but the filterspec only uses the first one it finds (gte), dropping the other (lte).
Anybody know how to achieve a negative filter like this through a custom FilterSpec?