Skip to content

Commit a2cac80

Browse files
committed
models: Add 'related_series' field to Series model
Closes getpatchwork#506 Signed-off-by: andrepapoti <andrepapoti@gmail.com>
1 parent 8c7aed3 commit a2cac80

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 5.0.4 on 2024-11-04 04:13
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
('patchwork', '0047_add_database_indexes'),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name='series',
14+
name='related_series',
15+
field=models.ManyToManyField(to='patchwork.series'),
16+
),
17+
]

patchwork/models.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ class Series(FilenameMixin, models.Model):
848848
help_text='An optional name to associate with '
849849
'the series, e.g. "John\'s PCI series".',
850850
)
851+
related_series = models.ManyToManyField('self')
851852
date = models.DateTimeField()
852853
submitter = models.ForeignKey(Person, on_delete=models.CASCADE)
853854
version = models.IntegerField(
@@ -934,6 +935,20 @@ def add_patch(self, patch, number):
934935

935936
return patch
936937

938+
def is_editable(self, user):
939+
if not user.is_authenticated:
940+
return False
941+
942+
if user.is_superuser:
943+
return True
944+
945+
try:
946+
person = Person.objects.get(user=user)
947+
except Exception:
948+
return False
949+
950+
return person == self.submitter
951+
937952
def get_absolute_url(self):
938953
# TODO(stephenfin): We really need a proper series view
939954
return reverse(

0 commit comments

Comments
 (0)