[PATCH v3 1/7] models: Add field for series dependencies

Adam Hassick ahassick at iol.unh.edu
Sat Nov 16 07:40:08 AEDT 2024


Adds a ManyToMany field to represent a dependency relationship between
patch series and a helper method to add dependencies.

Signed-off-by: Adam Hassick <ahassick at iol.unh.edu>
---
 .../migrations/0048_series_dependencies.py    | 23 ++++++++++++++++
 patchwork/models.py                           | 26 +++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100644 patchwork/migrations/0048_series_dependencies.py

diff --git a/patchwork/migrations/0048_series_dependencies.py b/patchwork/migrations/0048_series_dependencies.py
new file mode 100644
index 0000000..177079b
--- /dev/null
+++ b/patchwork/migrations/0048_series_dependencies.py
@@ -0,0 +1,23 @@
+# Generated by Django 5.0.6 on 2024-06-07 02:58
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ('patchwork', '0047_add_database_indexes'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='series',
+            name='dependencies',
+            field=models.ManyToManyField(
+                blank=True,
+                help_text='Optional dependencies on this patch.',
+                related_name='dependents',
+                related_query_name='dependent',
+                to='patchwork.series',
+            ),
+        ),
+    ]
diff --git a/patchwork/models.py b/patchwork/models.py
index a05db7f..714da9e 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -840,6 +840,16 @@ class Series(FilenameMixin, models.Model):
         Cover, related_name='series', null=True, on_delete=models.CASCADE
     )
 
+    # dependencies
+    dependencies = models.ManyToManyField(
+        'self',
+        symmetrical=False,
+        blank=True,
+        help_text='Optional dependencies on this patch.',
+        related_name='dependents',
+        related_query_name='dependent',
+    )
+
     # metadata
     name = models.CharField(
         max_length=255,
@@ -880,6 +890,22 @@ class Series(FilenameMixin, models.Model):
     def received_all(self):
         return self.total <= self.received_total
 
+    def add_dependencies(self, dependencies):
+        """Add dependencies to this series.
+
+        Helper method to add any found dependencies to this series.
+        The method will filter out self and any series not from the
+        same project.
+        """
+        self.dependencies.add(
+            *(
+                dep
+                for dep in dependencies
+                if dep.id != self.id and dep.project == self.project
+            )
+        )
+        self.save()
+
     def add_cover_letter(self, cover):
         """Add a cover letter to the series.
 
-- 
2.47.0



More information about the Patchwork mailing list