Django

Code

Ticket #12173 (closed: duplicate)

Opened 5 months ago

Last modified 2 months ago

hability to use OR in filterspecs

Reported by: fgallina Assigned to: nobody
Milestone: Component: django.contrib.admin
Version: SVN Keywords: filterspec, filter
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

filterspec_or_support.patch (2.1 kB) - added by fgallina on 11/06/09 00:01:36.
first proposal to support OR in filterspecs

Change History

11/06/09 00:01:36 changed by fgallina

  • attachment filterspec_or_support.patch added.

first proposal to support OR in filterspecs

11/06/09 00:02:37 changed by fgallina

  • needs_better_patch changed.
  • version changed from 1.1 to SVN.
  • needs_tests changed.
  • needs_docs changed.

02/05/10 07:35:02 changed by russellm

  • status changed from new to closed.
  • resolution set to duplicate.

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


Add/Change #12173 (hability to use OR in filterspecs)




Change Properties
Action