How do I get the class of a ManyToMany field in django models?
I have some fields in a model that are ManyToMany, I wa开发者_StackOverflow中文版nt the ManyToMany class itself, when I only have the field name. Is there any way I can retrieve it?
If model_obj
were an instance of the Model class that defines a ManyToManyField named foom2m
, then you could do this:
related_model = model_obj.__class_.foom2m.field.rel.to
精彩评论