diff --git a/rest_framework_api_key/migrations/0005_auto_id.py b/rest_framework_api_key/migrations/0005_auto_id.py new file mode 100644 index 0000000..dbb75ff --- /dev/null +++ b/rest_framework_api_key/migrations/0005_auto_id.py @@ -0,0 +1,26 @@ +# Generated by Django 2.2.2 on 2019-06-29 11:49 + +from django.db import migrations, models + +APP_NAME = "rest_framework_api_key" +MODEL_NAME = "apikey" +DEPENDENCIES = [(APP_NAME, "0004_prefix_hashed_key")] + + +class Migration(migrations.Migration): + + dependencies = DEPENDENCIES + + operations = [ + migrations.RemoveField(model_name=MODEL_NAME, name="id"), + migrations.AddField( + model_name=MODEL_NAME, + name="id", + field=models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ] diff --git a/rest_framework_api_key/models.py b/rest_framework_api_key/models.py index 15cf50c..2736053 100644 --- a/rest_framework_api_key/models.py +++ b/rest_framework_api_key/models.py @@ -15,12 +15,8 @@ def assign_key(self, obj: "AbstractAPIKey") -> str: key, prefix, hashed_key = self.key_generator.generate() except TypeError: # Compatibility with < 1.4 key, hashed_key = self.key_generator.generate() - pk = hashed_key prefix, hashed_key = split(hashed_key) - else: - pk = concatenate(prefix, hashed_key) - obj.id = pk obj.prefix = prefix obj.hashed_key = hashed_key @@ -63,9 +59,6 @@ class APIKeyManager(BaseAPIKeyManager): class AbstractAPIKey(models.Model): objects = APIKeyManager() - id = models.CharField( - max_length=100, unique=True, primary_key=True, editable=False - ) prefix = models.CharField(max_length=8, unique=True, editable=False) hashed_key = models.CharField(max_length=100, editable=False) created = models.DateTimeField(auto_now_add=True, db_index=True) diff --git a/tests/project/heroes/migrations/0003_auto_id.py b/tests/project/heroes/migrations/0003_auto_id.py new file mode 100644 index 0000000..23193b4 --- /dev/null +++ b/tests/project/heroes/migrations/0003_auto_id.py @@ -0,0 +1,26 @@ +# Generated by Django 2.2.2 on 2019-06-29 11:49 + +from django.db import migrations, models + +APP_NAME = "heroes" +MODEL_NAME = "heroapikey" +DEPENDENCIES = [(APP_NAME, "0002_prefix_hashed_key")] + + +class Migration(migrations.Migration): + + dependencies = DEPENDENCIES + + operations = [ + migrations.RemoveField(model_name=MODEL_NAME, name="id"), + migrations.AddField( + model_name=MODEL_NAME, + name="id", + field=models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ]