Wednesday, February 29, 2012

Re: Filtering model searches by a property (as opposed to a field)

On Wed, Feb 29, 2012 at 3:16 PM, Tom <> wrote:
> Is it not possible to filter based on a property?

queries are compiled to SQL to be sent and processed at the database;
properties are Python code, the database knows nothing about them.
that's why the compiler only allows you to use database fields on a

> What is the correct method for doing this?

the generic answer is to do it in Python, something like:

result = [ record in queryset if == value ]

but this can be very inefficient, and nowhere as flexible as Django's querysets.

much better is to translate the criteria into something the database
can process. In this case, find the beginning and end of the current
week and use a range filter.


You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment