From 67c64c0d1ce71085cff8ead23dfb0c26e8200fb8 Mon Sep 17 00:00:00 2001 From: Sylvain Gay Date: Thu, 2 May 2024 11:31:34 +0200 Subject: [PATCH] made cleaner migrations for loans --- inventory/migrations/0003_gameloan.py | 17 +++++++--- inventory/models.py | 3 ++ .../0002_abstractloan_delete_loan.py | 32 ------------------- loans/migrations/0002_delete_loan.py | 16 ++++++++++ loans/models.py | 1 + 5 files changed, 33 insertions(+), 36 deletions(-) delete mode 100644 loans/migrations/0002_abstractloan_delete_loan.py create mode 100644 loans/migrations/0002_delete_loan.py diff --git a/inventory/migrations/0003_gameloan.py b/inventory/migrations/0003_gameloan.py index 50752df..a0ac384 100644 --- a/inventory/migrations/0003_gameloan.py +++ b/inventory/migrations/0003_gameloan.py @@ -1,5 +1,6 @@ -# Generated by Django 4.2.8 on 2024-04-30 15:24 +# Generated by Django 4.2.8 on 2024-05-02 09:30 +import autoslug.fields from django.db import migrations, models import django.db.models.deletion @@ -7,7 +8,6 @@ import django.db.models.deletion class Migration(migrations.Migration): dependencies = [ - ('loans', '0002_abstractloan_delete_loan'), ('inventory', '0002_duration_range'), ] @@ -15,9 +15,18 @@ class Migration(migrations.Migration): migrations.CreateModel( name='GameLoan', fields=[ - ('abstractloan_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='loans.abstractloan')), + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='lent_object', unique=True)), + ('borrow_date', models.DateTimeField(auto_now_add=True)), + ('return_date', models.DateTimeField(null=True)), + ('mail', models.EmailField(max_length=254)), ('lent_object', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='inventory.game', verbose_name='jeu emprunté')), ], - bases=('loans.abstractloan',), + options={ + 'verbose_name': 'emprunt', + 'verbose_name_plural': 'emprunts', + 'ordering': ['borrow_date'], + 'abstract': False, + }, ), ] diff --git a/inventory/models.py b/inventory/models.py index 7162775..a8a2ce5 100644 --- a/inventory/models.py +++ b/inventory/models.py @@ -159,3 +159,6 @@ class GameLoan(AbstractLoan): Game, on_delete=models.CASCADE, verbose_name="jeu emprunté" ) + + class Meta(AbstractLoan.Meta): + abstract = False diff --git a/loans/migrations/0002_abstractloan_delete_loan.py b/loans/migrations/0002_abstractloan_delete_loan.py deleted file mode 100644 index 6a91cb8..0000000 --- a/loans/migrations/0002_abstractloan_delete_loan.py +++ /dev/null @@ -1,32 +0,0 @@ -# Generated by Django 4.2.8 on 2024-04-30 15:24 - -import autoslug.fields -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('loans', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='AbstractLoan', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='game', unique=True)), - ('borrow_date', models.DateTimeField(auto_now_add=True)), - ('return_date', models.DateTimeField(null=True)), - ('mail', models.EmailField(max_length=254)), - ], - options={ - 'verbose_name': 'emprunt', - 'verbose_name_plural': 'emprunts', - 'ordering': ['borrow_date'], - }, - ), - migrations.DeleteModel( - name='Loan', - ), - ] diff --git a/loans/migrations/0002_delete_loan.py b/loans/migrations/0002_delete_loan.py new file mode 100644 index 0000000..2bc49b9 --- /dev/null +++ b/loans/migrations/0002_delete_loan.py @@ -0,0 +1,16 @@ +# Generated by Django 4.2.8 on 2024-05-02 09:30 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('loans', '0001_initial'), + ] + + operations = [ + migrations.DeleteModel( + name='Loan', + ), + ] diff --git a/loans/models.py b/loans/models.py index 6c37694..ac52a77 100644 --- a/loans/models.py +++ b/loans/models.py @@ -12,6 +12,7 @@ class AbstractLoan(models.Model): lent_object_slug_field = "slug" class Meta: + abstract = True ordering=["borrow_date"] verbose_name = "emprunt" verbose_name_plural = "emprunts"