本文整理汇总了Python中xadmin.util.get_model_from_relation方法的典型用法代码示例。如果您正苦于以下问题:Python util.get_model_from_relation方法的具体用法?Python util.get_model_from_relation怎么用?Python util.get_model_from_relation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xadmin.util
的用法示例。
在下文中一共展示了util.get_model_from_relation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: formfield_for_dbfield
# 需要导入模块: from xadmin import util [as 别名]
# 或者: from xadmin.util import get_model_from_relation [as 别名]
def formfield_for_dbfield(self, formfield, db_field, **kwargs):
if formfield and self.model in self.admin_site._registry and isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
rel_model = get_model_from_relation(db_field)
if rel_model in self.admin_site._registry and self.has_model_perm(rel_model, 'add'):
add_url = self.get_model_url(rel_model, 'add')
formfield.widget = RelatedFieldWidgetWrapper(
formfield.widget, db_field.rel, add_url, self.get_model_url(self.model, 'add'))
return formfield
示例2: formfield_for_dbfield
# 需要导入模块: from xadmin import util [as 别名]
# 或者: from xadmin.util import get_model_from_relation [as 别名]
def formfield_for_dbfield(self, formfield, db_field, **kwargs):
if formfield and self.model in self.admin_site._registry and isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
rel_model = get_model_from_relation(db_field)
if rel_model in self.admin_site._registry and self.has_model_perm(rel_model, 'add'):
add_url = self.get_model_url(rel_model, 'add')
formfield.widget = RelatedFieldWidgetWrapper(
formfield.widget, db_field.remote_field, add_url, self.get_model_url(self.model, 'add'))
return formfield