On Tue, Jan 25, 2011 at 3:34 PM, kmpm <pe...@birchroad.net> wrote: > I have some issues with getting hold of the instance of a Model to which a > RelatedManager got contributed to. > Is that at all possible and if so, how? > From my_method below I can get hold of the model RelatedStuff by calling > self.model but that really doesn't get me there. > class MainStuff(models.Model): > .... > > class RelatedStuff(models.Model): > ... > main = models.ForeignKey(MainStuff) > objects = CustomManager() > class CustomManager(models.Manager): > use_for_related_fields=True > > def my_method(self): > #here I would like to access the instance of MainStuff to which this > got contributed >
What model instance? I think you are discounting the fact that CustomManager instances may be called without a related model instance. RelatedStuff.objects is an instance of CustomManager, so RelatedStuff.objects.my_method() is a valid method call, but what model instance do you think is relevant there? Cheers Tom -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.