Adding support for Django 2.0 BigAutoField. Closes #238.

This commit is contained in:
Dave Hall 2018-02-20 11:01:46 +00:00
parent b21fc06891
commit ba4a6af277
1 changed files with 13 additions and 6 deletions

View File

@ -15,16 +15,23 @@ except ImportError:
from django.contrib.contenttypes.generic import GenericForeignKey
INTEGER_FIELDS = (models.IntegerField, models.AutoField,)
BIG_INTEGER_FIELDS = (models.BigIntegerField,)
try:
BIG_INTEGER_FIELDS += (models.BigAutoField,)
except AttributeError: # Django < 2.0.
pass
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(pk.remote_field.model)
)
isinstance(pk, INTEGER_FIELDS) and
not isinstance(pk, BIG_INTEGER_FIELDS)
) or (
isinstance(pk, models.ForeignKey) and has_int_pk(pk.remote_field.model)
)