本文整理匯總了Python中django.contrib.contenttypes.generic.GenericRelation方法的典型用法代碼示例。如果您正苦於以下問題:Python generic.GenericRelation方法的具體用法?Python generic.GenericRelation怎麽用?Python generic.GenericRelation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.contrib.contenttypes.generic
的用法示例。
在下文中一共展示了generic.GenericRelation方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: contribute_to_class
# 需要導入模塊: from django.contrib.contenttypes import generic [as 別名]
# 或者: from django.contrib.contenttypes.generic import GenericRelation [as 別名]
def contribute_to_class(self, cls, name, *args, **kwargs):
@classproperty
def river(_self):
return RiverObject(_self)
self.field_name = name
self._add_to_class(cls, self.field_name + "_transition_approvals",
GenericRelation('%s.%s' % (TransitionApproval._meta.app_label, TransitionApproval._meta.object_name)))
self._add_to_class(cls, self.field_name + "_transitions", GenericRelation('%s.%s' % (Transition._meta.app_label, Transition._meta.object_name)))
if id(cls) not in workflow_registry.workflows:
self._add_to_class(cls, "river", river)
super(StateField, self).contribute_to_class(cls, name, *args, **kwargs)
if id(cls) not in workflow_registry.workflows:
post_save.connect(_on_workflow_object_saved, self.model, False, dispatch_uid='%s_%s_riverstatefield_post' % (self.model, name))
post_delete.connect(_on_workflow_object_deleted, self.model, False, dispatch_uid='%s_%s_riverstatefield_post' % (self.model, name))
workflow_registry.add(self.field_name, cls)
示例2: _register_model
# 需要導入模塊: from django.contrib.contenttypes import generic [as 別名]
# 或者: from django.contrib.contenttypes.generic import GenericRelation [as 別名]
def _register_model(admin, model):
if not hasattr(admin, 'revision_manager'):
admin.revision_manager = default_revision_manager
if not hasattr(admin, 'reversion_format'):
admin.reversion_format = 'json'
if not admin.revision_manager.is_registered(model):
inline_fields = []
for inline in getattr(admin, 'inlines', []):
inline_model = inline.model
if getattr(inline, 'generic_inline', False):
ct_field = getattr(inline, 'ct_field', 'content_type')
ct_fk_field = getattr(inline, 'ct_fk_field', 'object_id')
for field in model._meta.many_to_many:
if isinstance(field, GenericRelation) and field.rel.to == inline_model and field.object_id_field_name == ct_fk_field and field.content_type_field_name == ct_field:
inline_fields.append(field.name)
_autoregister(admin, inline_model)
else:
fk_name = getattr(inline, 'fk_name', None)
if not fk_name:
for field in inline_model._meta.fields:
if isinstance(field, (models.ForeignKey, models.OneToOneField)) and issubclass(model, field.rel.to):
fk_name = field.name
_autoregister(admin, inline_model, follow=[fk_name])
if not inline_model._meta.get_field(fk_name).rel.is_hidden():
accessor = inline_model._meta.get_field(
fk_name).related.get_accessor_name()
inline_fields.append(accessor)
_autoregister(admin, model, inline_fields)