Get relationship model name of object Django

旧巷老猫 提交于 2020-03-05 01:43:07

问题


I'm trying to get the model name for different objects:

This kinda works:

last_profile = Profile.object.last()

profile.__class__._meta.verbose_name // 'profile'

But not for a compounded model name such ProfileLogin:

last_profile_login = ProfileLogin.objects.last()
last_profile_login.__class__._meta.verbose_name // 'profile login'

I would like the last example to be profile_login.

The reason, I'm doing this is to create a dynamic query using filter().

来源:https://stackoverflow.com/questions/60326533/get-relationship-model-name-of-object-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!