Python django.contrib.contenttypes.generic.GenericRelation() Examples
The following are 2
code examples of django.contrib.contenttypes.generic.GenericRelation().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.contrib.contenttypes.generic
, or try the search function
.
Example #1
Source File: state.py From django-river with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #2
Source File: xversion.py From devops with MIT License | 5 votes |
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)