On Thu, Sep 11, 2008 at 2:06 AM, MikeHowarth <[EMAIL PROTECTED]>wrote:
> > I was wondering if anyone could help me. > > I currently have a Product model which has a many to many association > linked back to itself for related items. > > When returning the related items, I want to filter out any which are > not currently flagged as active. > > Initially I thought about doing something like this: > > def _get_related_items(self): > self.related_items.exclude(active=0) > > related_items = property(_get_related_items) > > However I've managed to create a recursive query. >From a brief look, it seems you're replacing the original related_items attribute with your new one, which means you can never access the old one. When you try to get self.related_items in _get_related_items(), it accesses your new property, which calls _get_related_items(), and so on. This has nothing to do with Django, it's just a Python thing. I'd just call the _get_related_items() method directly and change the name: def active_related_items(self): return self.related_items.exclude(active=0) If you're really set on accessing related_items through the property as you've got it written, just change the name of the original field to all_related_items or something so there's no name collision. Steve > > > Could anyone clarify what I need to do be doing to acheive the desired > filtering? > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---