开发者

How to get Class Model name from ManyToManyField in Django

I need to get Class Model name from #django.db.models.fields.re开发者_StackOverflow中文版lated.ManyToManyField object.For example:

class Source(models.Model):
    groups = models.ManyToManyField(Group)

    def generated_sql(self):
        print [f.name for f in self._meta.many_to_many]

        #tehere I need to get Class Model name for f, in this case will be: Group

Thanks in advance


groups = models.ManyToManyField(Group)

def generated_sql(self):
    print [(f.name, f.related.parent_model) for f in self._meta.many_to_many]

iPython ftw

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜