简体   繁体   中英

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

I have some fields in a model that are ManyToMany, I want the ManyToMany class itself, when I only have the field name. Is there any way I can retrieve it?

如果model_obj是Model类的实例,该实例定义了一个名为foom2m的ManyToManyField,则可以执行以下操作:

related_model = model_obj.__class_.foom2m.field.rel.to

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM