I have it:
Class A(models.Model):
name = models.CharField(max_length=50)
Class B(models.Model):
a = models.ForeignKey(A)
class C(models.Model):
a = models.ManyToManyField(A)
When I need an attribute ain an object C:
related_manager = getattr(object_c,'a')
and this gives me ManyRelatedManager, but the problem is that I need an attribute ain the object B:
object_b2 = getattr(object_b,'a')
this gives me an object of class B and I need to know if ForeignKey or ManyToManyField, I mean, I need to getattr (something, "some_attribute") and get the models. * Not an object in itself.
source
share