Opened 15 years ago

Closed 15 years ago

#12173 closed (duplicate)

hability to use OR in filterspecs

Reported by: Fabián Ezequiel Gallina Owned by: nobody
Component: contrib.admin Version: dev
Severity: Keywords: filterspec, filter
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently when creating filterspecs we only can combine several rules using AND only.

This patch adds the hability to use OR in the query.

Why this could be useful?

Suppose we have a Taxes model which contains a due_date field and a payed_date field and we want to filter the non due taxes.

So non due taxes would be:

Q(due_date__gt=datetime.date.today()) | Q(payed_date__is_null=False)

How we do that?

When creating a filterspec prepend the value of FILTERSPEC_OR_PREFIX (the value in the patch is '__or__') to your fields like this:

[...]

        self.links = (
            (_('Non Due'), {'%s__gte' % self.field.name: str(today.date()),
                              '__or__payed_date__isnull' : 'False'}),
        )

[...]

PD: I also fixed a little typo in the line 208 (comment)

Attachments (1)

filterspec_or_support.patch (2.1 KB ) - added by Fabián Ezequiel Gallina 15 years ago.
first proposal to support OR in filterspecs

Download all attachments as: .zip

Change History (3)

by Fabián Ezequiel Gallina, 15 years ago

Attachment: filterspec_or_support.patch added

first proposal to support OR in filterspecs

comment:1 by Fabián Ezequiel Gallina, 15 years ago

Version: 1.1SVN

comment:2 by Russell Keith-Magee, 15 years ago

Resolution: duplicate
Status: newclosed

#5833 covers a much broader range of improvements for filterspecs.

Note: See TracTickets for help on using tickets.
Back to Top