Exemple #1
0
 def _reversion_introspect_inline_admin(self, inline):
     inline_model = None
     follow_field = None
     fk_name = None
     if issubclass(inline, GenericInlineModelAdmin):
         inline_model = inline.model
         ct_field = inline.ct_field
         fk_name = inline.ct_fk_field
         for field in self.model._meta.virtual_fields:
             if (
                 isinstance(field, GenericRelation) and
                 remote_model(field) == inline_model and
                 field.object_id_field_name == fk_name and
                 field.content_type_field_name == ct_field
             ):
                 follow_field = field.name
                 break
     elif issubclass(inline, options.InlineModelAdmin):
         inline_model = inline.model
         fk_name = inline.fk_name
         if not fk_name:
             for field in inline_model._meta.get_fields():
                 if (
                     isinstance(field, (models.ForeignKey, models.OneToOneField)) and
                     issubclass(self.model, remote_model(field))
                 ):
                     fk_name = field.name
                     break
         if fk_name and not remote_field(inline_model._meta.get_field(fk_name)).is_hidden():
             field = inline_model._meta.get_field(fk_name)
             accessor = remote_field(field).get_accessor_name()
             follow_field = accessor
     return inline_model, follow_field
Exemple #2
0
def has_int_pk(model):
    """Tests whether the given model has an integer primary key."""
    pk = model._meta.pk
    return ((isinstance(pk, (models.IntegerField, models.AutoField))
             and not isinstance(pk, models.BigIntegerField))
            or (isinstance(pk, models.ForeignKey)
                and has_int_pk(remote_model(pk))))
def has_int_pk(model):
    """Tests whether the given model has an integer primary key."""
    pk = model._meta.pk
    return (
        (
            isinstance(pk, (models.IntegerField, models.AutoField)) and
            not isinstance(pk, models.BigIntegerField)
        ) or (
            isinstance(pk, models.ForeignKey) and has_int_pk(remote_model(pk))
        )
    )