From a2cac80ec97b64c0090fc1b6f8eae52ac73af20a Mon Sep 17 00:00:00 2001 From: andrepapoti Date: Mon, 18 Mar 2024 11:34:26 -0300 Subject: [PATCH] models: Add 'related_series' field to Series model Closes #506 Signed-off-by: andrepapoti --- .../migrations/0048_series_related_series.py | 17 +++++++++++++++++ patchwork/models.py | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 patchwork/migrations/0048_series_related_series.py diff --git a/patchwork/migrations/0048_series_related_series.py b/patchwork/migrations/0048_series_related_series.py new file mode 100644 index 00000000..401345a2 --- /dev/null +++ b/patchwork/migrations/0048_series_related_series.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.4 on 2024-11-04 04:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('patchwork', '0047_add_database_indexes'), + ] + + operations = [ + migrations.AddField( + model_name='series', + name='related_series', + field=models.ManyToManyField(to='patchwork.series'), + ), + ] diff --git a/patchwork/models.py b/patchwork/models.py index a05db7f9..28183e7d 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -848,6 +848,7 @@ class Series(FilenameMixin, models.Model): help_text='An optional name to associate with ' 'the series, e.g. "John\'s PCI series".', ) + related_series = models.ManyToManyField('self') date = models.DateTimeField() submitter = models.ForeignKey(Person, on_delete=models.CASCADE) version = models.IntegerField( @@ -934,6 +935,20 @@ def add_patch(self, patch, number): return patch + def is_editable(self, user): + if not user.is_authenticated: + return False + + if user.is_superuser: + return True + + try: + person = Person.objects.get(user=user) + except Exception: + return False + + return person == self.submitter + def get_absolute_url(self): # TODO(stephenfin): We really need a proper series view return reverse(