On 4/11/07, Paolo Dina <[EMAIL PROTECTED]> wrote:
>
> In my model there is model method I'd like to use for filtering.
> Is it possible? I have put it in form of property, but when I use it
> with field lookup syntax I get an error.

No. In your example 'visible' isn't a field in your database. Filter
is an operation that is converted into a database query, so methods on
your Django model can't be used as part of a query.

Your best option would be to add visible as a property of the manager,
rather than the model, and define that manager operation as an alias
for the underlying database operation. See
http://www.djangoproject.com/documentation/model-api/#custom-managers
for more details, but the short version is something like:

class ContentManager(models.Manager):
    def visible(self):
        return self.filter(priv=False, pub_date__lt=datetime.now())

class Content(models.Model):
    objects = ContentManager()
    # Rest of model as before.

Then, when you want to use visible, Content.objects.visible() will
return a query set that contains all visible objects.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to