本文整理匯總了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