Code

Opened 4 years ago

Closed 4 years ago

#12173 closed (duplicate)

hability to use OR in filterspecs

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

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 fgallina 4 years ago.
first proposal to support OR in filterspecs

Download all attachments as: .zip

Change History (3)

Changed 4 years ago by fgallina

first proposal to support OR in filterspecs

comment:1 Changed 4 years ago by fgallina

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.1 to SVN

comment:2 Changed 4 years ago by russellm

  • Resolution set to duplicate
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.