本文整理汇总了Python中xadmin.views.detail.DetailAdminUtil方法的典型用法代码示例。如果您正苦于以下问题:Python detail.DetailAdminUtil方法的具体用法?Python detail.DetailAdminUtil怎么用?Python detail.DetailAdminUtil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xadmin.views.detail
的用法示例。
在下文中一共展示了detail.DetailAdminUtil方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_version_object
# 需要导入模块: from xadmin.views import detail [as 别名]
# 或者: from xadmin.views.detail import DetailAdminUtil [as 别名]
def get_version_object(self, version):
obj_version = version._object_version
obj = obj_version.object
obj._state.db = self.obj._state.db
for field_name, pks in obj_version.m2m_data.items():
f = self.opts.get_field(field_name)
if f.rel and isinstance(f.rel, models.ManyToManyRel):
setattr(obj, f.name, f.rel.to._default_manager.get_query_set(
).filter(pk__in=pks).all())
detail = self.get_model_view(DetailAdminUtil, self.model, obj)
return obj, detail
示例2: get_version_object
# 需要导入模块: from xadmin.views import detail [as 别名]
# 或者: from xadmin.views.detail import DetailAdminUtil [as 别名]
def get_version_object(self, version):
obj_version = version.object_version
obj = obj_version.object
obj._state.db = self.obj._state.db
for field_name, pks in obj_version.m2m_data.items():
f = self.opts.get_field(field_name)
if f.rel and isinstance(f.rel, models.ManyToManyRel):
setattr(obj, f.name, f.rel.to._default_manager.get_query_set(
).filter(pk__in=pks).all())
detail = self.get_model_view(DetailAdminUtil, self.model, obj)
return obj, detail
示例3: _hack_inline_formset_initial
# 需要导入模块: from xadmin.views import detail [as 别名]
# 或者: from xadmin.views.detail import DetailAdminUtil [as 别名]
def _hack_inline_formset_initial(self, revision_view, formset):
"""Hacks the given formset to contain the correct initial data."""
# Now we hack it to push in the data from the revision!
initial = []
related_versions = self.get_related_versions(
revision_view.org_obj, revision_view.version, formset)
formset.related_versions = related_versions
for related_obj in formset.queryset:
if smart_text(related_obj.pk) in related_versions:
initial.append(
related_versions.pop(smart_text(related_obj.pk)).field_dict)
else:
initial_data = model_to_dict(related_obj)
initial_data["DELETE"] = True
initial.append(initial_data)
for related_version in related_versions.values():
initial_row = related_version.field_dict
pk_name = ContentType.objects.get_for_id(
related_version.content_type_id).model_class()._meta.pk.name
del initial_row[pk_name]
initial.append(initial_row)
# Reconstruct the forms with the new revision data.
formset.initial = initial
formset.forms = [formset._construct_form(
n) for n in xrange(len(initial))]
# Hack the formset to force a save of everything.
def get_changed_data(form):
return [field.name for field in form.fields]
for form in formset.forms:
form.has_changed = lambda: True
form._get_changed_data = partial(get_changed_data, form=form)
def total_form_count_hack(count):
return lambda: count
formset.total_form_count = total_form_count_hack(len(initial))
if self.request.method == 'GET' and formset.helper and formset.helper.layout:
helper = formset.helper
cls_str = str if six.PY3 else basestring
helper.filter(cls_str).wrap(InlineDiffField)
fake_admin_class = type(str('%s%sFakeAdmin' % (self.opts.app_label, self.opts.model_name)), (object, ), {'model': self.model})
for form in formset.forms:
instance = form.instance
if instance.pk:
form.detail = self.get_view(
DetailAdminUtil, fake_admin_class, instance)
示例4: _hack_inline_formset_initial
# 需要导入模块: from xadmin.views import detail [as 别名]
# 或者: from xadmin.views.detail import DetailAdminUtil [as 别名]
def _hack_inline_formset_initial(self, revision_view, formset):
"""Hacks the given formset to contain the correct initial data."""
# Now we hack it to push in the data from the revision!
initial = []
related_versions = self.get_related_versions(
revision_view.org_obj, revision_view.version, formset)
formset.related_versions = related_versions
for related_obj in formset.queryset:
if smart_text(related_obj.pk) in related_versions:
initial.append(
related_versions.pop(smart_text(related_obj.pk)).field_dict)
else:
initial_data = model_to_dict(related_obj)
initial_data["DELETE"] = True
initial.append(initial_data)
for related_version in related_versions.values():
initial_row = related_version.field_dict
pk_name = ContentType.objects.get_for_id(
related_version.content_type_id).model_class()._meta.pk.name
del initial_row[pk_name]
initial.append(initial_row)
# Reconstruct the forms with the new revision data.
formset.initial = initial
formset.forms = [formset._construct_form(
n) for n in xrange(len(initial))]
# Hack the formset to force a save of everything.
def get_changed_data(form):
return [field.name for field in form.fields]
for form in formset.forms:
form.has_changed = lambda: True
form._get_changed_data = partial(get_changed_data, form=form)
def total_form_count_hack(count):
return lambda: count
formset.total_form_count = total_form_count_hack(len(initial))
if self.request.method == 'GET' and formset.helper and formset.helper.layout:
helper = formset.helper
cls_str = str
helper.filter(cls_str).wrap(InlineDiffField)
fake_admin_class = type(str('%s%sFakeAdmin' % (self.opts.app_label, self.opts.model_name)), (object, ), {'model': self.model})
for form in formset.forms:
instance = form.instance
if instance.pk:
form.detail = self.get_view(
DetailAdminUtil, fake_admin_class, instance)
示例5: _hack_inline_formset_initial
# 需要导入模块: from xadmin.views import detail [as 别名]
# 或者: from xadmin.views.detail import DetailAdminUtil [as 别名]
def _hack_inline_formset_initial(self, revision_view, formset):
"""Hacks the given formset to contain the correct initial data."""
# Now we hack it to push in the data from the revision!
initial = []
related_versions = self.get_related_versions(
revision_view.org_obj, revision_view.version, formset)
formset.related_versions = related_versions
for related_obj in formset.queryset:
if unicode(related_obj.pk) in related_versions:
initial.append(
related_versions.pop(unicode(related_obj.pk)).field_dict)
else:
initial_data = model_to_dict(related_obj)
initial_data["DELETE"] = True
initial.append(initial_data)
for related_version in related_versions.values():
initial_row = related_version.field_dict
pk_name = ContentType.objects.get_for_id(
related_version.content_type_id).model_class()._meta.pk.name
del initial_row[pk_name]
initial.append(initial_row)
# Reconstruct the forms with the new revision data.
formset.initial = initial
formset.forms = [formset._construct_form(
n) for n in xrange(len(initial))]
# Hack the formset to force a save of everything.
def get_changed_data(form):
return [field.name for field in form.fields]
for form in formset.forms:
form.has_changed = lambda: True
form._get_changed_data = partial(get_changed_data, form=form)
def total_form_count_hack(count):
return lambda: count
formset.total_form_count = total_form_count_hack(len(initial))
if self.request.method == 'GET' and formset.helper and formset.helper.layout:
helper = formset.helper
helper.filter(basestring).wrap(InlineDiffField)
fake_admin_class = type(str('%s%sFakeAdmin' % (self.opts.app_label, self.opts.model_name)), (object, ), {'model': self.model})
for form in formset.forms:
instance = form.instance
if instance.pk:
form.detail = self.get_view(
DetailAdminUtil, fake_admin_class, instance)