Wednesday, February 29, 2012

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

Hi all,

I have the following model:

class Todo(models.Model):
name = models.CharField(max_length=200)
due_date = models.DateTimeField()
location = models.CharField(max_length=200)
type = models.CharField(max_length=4, choices=TODO_TYPES)
owner = models.ForeignKey(User, verbose_name='owner')
done = models.BooleanField(default=False)
def _get_due_week(self):
return int(self.due_date.strftime("%W"))
due_week = property(_get_due_week)
def __unicode__(self):

and this search code:

user = request.user
this_week = int(date.strftime("%W"))
this_weeks_todos =

But I get:

"Cannot resolve keyword 'due_week' into field. Choices are: done,
due_date, id, location, name, owner, type"

Is it not possible to filter based on a property?

What is the correct method for doing this?

Thanks in advance for your help.


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