Tuesday, January 25, 2011

Getting hold of an instance of a model from inside RelatedManager

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


--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment