Hi, I wonder whether there's a way to achieve the following: Let's assume I've two models User and Fav with a 1-to-many relation. Favs have a rating.
Now, I'm interested in a User's highest rated Fav. I could create a custom function or User instance method to call "user.favs.filter(..).order_by(...)[0]", but can I also create a function in such a way that the call will look like "user.favs.best()"? For models, I can overwrite the Manager and create custom methods. Can I also customize the RelatedManager "user.favs"? Thanks, PS: I looked into the source and guessing from that rather complex meta-programming code, I'm afraid, it cannot be done. The RelatedManager of a ForeignRelatedObjectsDescriptor is based on the related object's default manager. A way to extend this might be this: class Fav(models.Model): user = models.ForeignKey(User, related_name='favs') class user_favs_mixin: def best(self): ... The ForeignRelatedObjectsDescriptor would the look for the innerclass and add it to the list of superclases of its dynamic RelatedManager class definition. But it might be too much magic... -- Stefan Matthias Aust --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---