[PATCH v5 2/7] models: Add 'Series' model and related models

Stephen Finucane stephen at that.guru
Mon Oct 17 23:13:47 AEDT 2016


On 11 Oct 12:35, Andy Doan wrote:
> On 10/09/2016 05:25 PM, Stephen Finucane wrote:
> > Add a series model. This model is intentionally very minimal to allow
> > as much dynaminism as possible. It is expected that patches will be
> > migrated between series as new data is provided.
> > 
> > Signed-off-by: Stephen Finucane <stephen at that.guru>
> > ---
> 
> > diff --git a/patchwork/models.py b/patchwork/models.py
> > index 28e9861..4a55c1d 100644
> > --- a/patchwork/models.py
> > +++ b/patchwork/models.py
> > @@ -293,7 +293,7 @@ class EmailMixin(models.Model):
> 
> >  class CoverLetter(Submission):
> > -    pass
> > +
> > +    @property
> > +    def series(self):
> > +        """Get a simple series reference.
> > +
> > +        Return the last series revision that (ordered by date) that
> > +        this submission is a member of.
> > +
> > +        .. warning::
> > +          Be judicious in your use of this. For example, do not use it
> > +          in list templates as doing so will result in a new query for
> > +          each item in the list.
> > +        """
> > +        # NOTE(stephenfin): We don't use 'latest()' here, as this can raise an
> > +        # exception if no series revisions exist
> > +        return self.series_revisions.order_by('-date').first()
> 
> I see this method both here and in the Patch class. Couldn't we just put
> it in the Submission class once and avoid the duplication?

I remembered why I didn't do this: Submission doesn't have a
'series_revisions' field so I couldn't include it. Duplication is bad,
but exposing a non-working function seemed worse.

Stephen


More information about the Patchwork mailing list