diff mbox series

[v1,2/9] models: Add field for series dependencies

Message ID 20240617221900.156155-2-ahassick@iol.unh.edu
State Changes Requested
Headers show
Series [v1,1/9] api: Add fields to series detail view | expand

Commit Message

Adam Hassick June 17, 2024, 10:18 p.m. UTC
Add a ManyToMany field to represent a dependency relationship between
patch series.

Signed-off-by: Adam Hassick <ahassick@iol.unh.edu>
---
 patchwork/models.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Stephen Finucane July 12, 2024, 3:35 p.m. UTC | #1
On Mon, 2024-06-17 at 18:18 -0400, Adam Hassick wrote:
> Add a ManyToMany field to represent a dependency relationship between
> patch series.
> 
> Signed-off-by: Adam Hassick <ahassick@iol.unh.edu>

Two comments below but LGTM.

Reviewed-by: Stephen Finucane <stephen@that.guru>

> ---
>  patchwork/models.py | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/patchwork/models.py b/patchwork/models.py
> index 9a619bc..6f6a32d 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,13 @@ class Series(FilenameMixin, models.Model):
>      def received_all(self):
>          return self.total <= self.received_total
>  
> +    def add_dependencies(self, dependencies):
> +        # for dependency in dependencies:
> +        #     dependency.dependents.add(self)
> +        #     dependency.save()

I assume this is from testing and should be dropped?

> +        self.dependencies.add(*dependencies)

I have questions around validating this to prevent e.g. linking to self, but
that's for later.

> +        self.save()
> +
>      def add_cover_letter(self, cover):
>          """Add a cover letter to the series.
>
Adam Hassick July 12, 2024, 7:35 p.m. UTC | #2
On Fri, Jul 12, 2024 at 11:35 AM Stephen Finucane <stephen@that.guru> wrote:
>
> On Mon, 2024-06-17 at 18:18 -0400, Adam Hassick wrote:
> > Add a ManyToMany field to represent a dependency relationship between
> > patch series.
> >
> > Signed-off-by: Adam Hassick <ahassick@iol.unh.edu>
>
> Two comments below but LGTM.
>
> Reviewed-by: Stephen Finucane <stephen@that.guru>
>
> > ---
> >  patchwork/models.py | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> >
> > diff --git a/patchwork/models.py b/patchwork/models.py
> > index 9a619bc..6f6a32d 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,13 @@ class Series(FilenameMixin, models.Model):
> >      def received_all(self):
> >          return self.total <= self.received_total
> >
> > +    def add_dependencies(self, dependencies):
> > +        # for dependency in dependencies:
> > +        #     dependency.dependents.add(self)
> > +        #     dependency.save()
>
> I assume this is from testing and should be dropped?

Yes, will do.

> > +        self.dependencies.add(*dependencies)
>
> I have questions around validating this to prevent e.g. linking to self, but
> that's for later.

I can add a check here to make sure the dependent is not self and is
of the same project.
I don't think it makes much sense to depend on a patch from a
different project either.

> > +        self.save()
> > +
> >      def add_cover_letter(self, cover):
> >          """Add a cover letter to the series.
> >
>
diff mbox series

Patch

diff --git a/patchwork/models.py b/patchwork/models.py
index 9a619bc..6f6a32d 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,13 @@  class Series(FilenameMixin, models.Model):
     def received_all(self):
         return self.total <= self.received_total
 
+    def add_dependencies(self, dependencies):
+        # for dependency in dependencies:
+        #     dependency.dependents.add(self)
+        #     dependency.save()
+        self.dependencies.add(*dependencies)
+        self.save()
+
     def add_cover_letter(self, cover):
         """Add a cover letter to the series.