开发者

How do I get the class of a ManyToMany field in django models?

开发者 https://www.devze.com 2023-01-05 01:28 出处:网络
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 a

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号