From 5bb006173f4e78a01b0e5719eca88d5c5d232503 Mon Sep 17 00:00:00 2001 From: Marcus Furlong Date: Sun, 4 Feb 2024 22:17:30 -0500 Subject: [PATCH] use correct module uniqeness constraint --- modules/migrations/0002_auto_20240204_2214.py | 33 +++++++++++++++++++ .../migrations/0003_alter_module_options.py | 17 ++++++++++ modules/models.py | 11 ++++--- 3 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 modules/migrations/0002_auto_20240204_2214.py create mode 100644 modules/migrations/0003_alter_module_options.py diff --git a/modules/migrations/0002_auto_20240204_2214.py b/modules/migrations/0002_auto_20240204_2214.py new file mode 100644 index 00000000..6b44390d --- /dev/null +++ b/modules/migrations/0002_auto_20240204_2214.py @@ -0,0 +1,33 @@ +# Generated by Django 3.2.23 on 2024-02-04 22:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('arch', '0001_initial'), + ('modules', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='module', + name='context', + field=models.CharField(max_length=255), + ), + migrations.AlterField( + model_name='module', + name='name', + field=models.CharField(max_length=255), + ), + migrations.AlterField( + model_name='module', + name='stream', + field=models.CharField(max_length=255), + ), + migrations.AlterUniqueTogether( + name='module', + unique_together={('name', 'stream', 'version', 'context', 'arch')}, + ), + ] diff --git a/modules/migrations/0003_alter_module_options.py b/modules/migrations/0003_alter_module_options.py new file mode 100644 index 00000000..fb00cb48 --- /dev/null +++ b/modules/migrations/0003_alter_module_options.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.23 on 2024-02-04 22:40 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('modules', '0002_auto_20240204_2214'), + ] + + operations = [ + migrations.AlterModelOptions( + name='module', + options={'ordering': ('name', 'stream'), 'verbose_name': 'Module', 'verbose_name_plural': 'Modules'}, + ), + ] diff --git a/modules/models.py b/modules/models.py index 2879bb37..de4918b4 100644 --- a/modules/models.py +++ b/modules/models.py @@ -24,10 +24,10 @@ class Module(models.Model): - name = models.CharField(unique=True, max_length=255) - stream = models.CharField(unique=True, max_length=255) + name = models.CharField(max_length=255) + stream = models.CharField(max_length=255) version = models.CharField(max_length=255) - context = models.CharField(unique=True, max_length=255) + context = models.CharField(max_length=255) arch = models.ForeignKey(PackageArchitecture, on_delete=models.CASCADE) repo = models.ForeignKey(Repository, on_delete=models.CASCADE) packages = models.ManyToManyField(Package, blank=True) @@ -35,10 +35,11 @@ class Module(models.Model): class Meta: verbose_name = 'Module' verbose_name_plural = 'Modules' - ordering = ('name',) + unique_together = ('name', 'stream', 'version', 'context', 'arch',) + ordering = ('name', 'stream',) def __str__(self): - return self.name + return f'{self.name}-{self.stream}' def get_absolute_url(self): return reverse('modules:module_detail', args=[str(self.id)])