Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     """Initializes the VersionAdmin"""
     super(VersionAdmin, self).__init__(*args, **kwargs)
     # Automatically register models if required.
     if not is_registered(self.model):
         inline_fields = []
         for inline in self.inlines:
             inline_model = inline.model
             self._autoregister(inline_model)
             if issubclass(inline,
                           (admin.TabularInline, admin.StackedInline)):
                 fk_name = inline.fk_name
                 if not fk_name:
                     for field in inline_model._meta.fields:
                         if isinstance(field,
                                       models.ForeignKey) and issubclass(
                                           self.model, field.rel.to):
                             fk_name = field.name
                 accessor = inline_model._meta.get_field(
                     fk_name
                 ).rel.related_name or inline_model.__name__.lower(
                 ) + "_set"
                 inline_fields.append(accessor)
             elif issubclass(inline, GenericInlineModelAdmin):
                 ct_field = inline.ct_field
                 ct_fk_field = inline.ct_fk_field
                 for field in self.model._meta.many_to_many:
                     if isinstance(
                             field, GenericRelation
                     ) and field.object_id_field_name == ct_fk_field and field.content_type_field_name == ct_field:
                         inline_fields.append(field.name)
         self._autoregister(self.model, inline_fields)
Ejemplo n.º 2
0
 def _autoregister(self, model, follow=None):
     """Registers a model with reversion, if required."""
     if not is_registered(model):
         follow = follow or []
         for parent_cls, field in model._meta.parents.items():
             follow.append(field.name)
             self._autoregister(parent_cls)
         register(model, follow=follow)
Ejemplo n.º 3
0
 def _autoregister(self, model, follow=None):
     """Registers a model with reversion, if required."""
     if not is_registered(model):
         follow = follow or []
         for parent_cls, field in model._meta.parents.items():
             follow.append(field.name)
             self._autoregister(parent_cls)
         register(model, follow=follow)
Ejemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     """Initializes the VersionAdmin"""
     super(VersionAdmin, self).__init__(*args, **kwargs)
     # Automatically register models if required.
     if not is_registered(self.model):
         inline_fields = []
         for inline in self.inlines:
             inline_model = inline.model
             self._autoregister(inline_model)
             if issubclass(inline, (admin.TabularInline, admin.StackedInline)):
                 fk_name = inline.fk_name
                 if not fk_name:
                     for field in inline_model._meta.fields:
                         if isinstance(field, models.ForeignKey) and issubclass(self.model, field.rel.to):
                             fk_name = field.name
                 accessor = inline_model._meta.get_field(fk_name).rel.related_name or inline_model.__name__.lower() + "_set"
                 inline_fields.append(accessor)
             elif issubclass(inline, GenericInlineModelAdmin):
                 ct_field = inline.ct_field
                 ct_fk_field = inline.ct_fk_field
                 for field in self.model._meta.many_to_many:
                     if isinstance(field, GenericRelation) and field.object_id_field_name == ct_fk_field and field.content_type_field_name == ct_field:
                         inline_fields.append(field.name)
         self._autoregister(self.model, inline_fields)