Skip to content

Commit cb9686f

Browse files
stephenfinfstachura
authored andcommitted
models: Add submission labels
Labels are arbitrary bits of metadata attached to a submission. They can be used to signify priority, category, or other similar information. They can also be used to filter patches and identify the ones most interesting to a given user. Labels can be associated with a project to ensure that one project can use a totally different set of labels to another and to, in the future, allow a project administrator to use their own labels. However, they can also be global, which is useful for things that would be common across multiple projects such as "RFC".
1 parent aae5d02 commit cb9686f

4 files changed

Lines changed: 133 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<django-objects version="1.0">
3+
<object model="patchwork.label" pk="1">
4+
<field name="project" rel="ManyToOneRel" to="patchwork.project"><None></None></field>
5+
<field name="name" type="CharField">RFC</field>
6+
<field name="description" type="TextField">"RFC" stands for "Request for Comment", which tells maintainers that they should review your patch thoroughly and provide feedback. RFC is typically used when sending feature patches for the first time, or anytime the patch is more than just a simple bug fix.</field>
7+
<field name="color" type="PositiveIntegerField">#EDEDED</field>
8+
</object>
9+
</django-objects>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Generated by Django 6.0.7 on 2026-07-31 21:26
2+
3+
import django.db.models.deletion
4+
import patchwork.fields
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
dependencies = [
10+
('patchwork', '0048_series_dependencies'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Label',
16+
fields=[
17+
(
18+
'id',
19+
models.AutoField(
20+
auto_created=True,
21+
primary_key=True,
22+
serialize=False,
23+
verbose_name='ID',
24+
),
25+
),
26+
(
27+
'name',
28+
models.CharField(
29+
help_text='The label value.', max_length=25
30+
),
31+
),
32+
(
33+
'description',
34+
models.TextField(
35+
blank=True,
36+
help_text='A description of what the label is and when it should be applied.',
37+
null=True,
38+
),
39+
),
40+
(
41+
'color',
42+
patchwork.fields.ColorField(
43+
help_text='The color code to use in the UI.'
44+
),
45+
),
46+
(
47+
'project',
48+
models.ForeignKey(
49+
blank=True,
50+
help_text='The project this label is associated with. If unset, this label is global to the instance',
51+
null=True,
52+
on_delete=django.db.models.deletion.CASCADE,
53+
related_name='labels',
54+
related_query_name='label',
55+
to='patchwork.project',
56+
),
57+
),
58+
],
59+
options={
60+
'ordering': ['name'],
61+
'unique_together': {('project', 'name')},
62+
},
63+
),
64+
migrations.AddField(
65+
model_name='cover',
66+
name='labels',
67+
field=models.ManyToManyField(to='patchwork.label'),
68+
),
69+
migrations.AddField(
70+
model_name='patch',
71+
name='labels',
72+
field=models.ManyToManyField(to='patchwork.label'),
73+
),
74+
]

‎patchwork/models.py‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from django.utils.functional import cached_property
1919
from django.utils import timezone as tz_utils
2020

21-
from patchwork.fields import HashField
21+
from patchwork.fields import HashField, ColorField
2222
from patchwork.hasher import hash_diff
2323

2424
if settings.ENABLE_REST_API:
@@ -256,6 +256,43 @@ class Meta:
256256
ordering = ['ordering']
257257

258258

259+
class Label(models.Model):
260+
"""Labels for patches.
261+
262+
Labels are arbitrary bits of metadata attached to a patch. They can
263+
be used to signify priority, category, or other similar information.
264+
They can also be used to filter patches and identify the ones most
265+
interesting to a given user.
266+
"""
267+
268+
project = models.ForeignKey(
269+
Project,
270+
related_name='labels',
271+
related_query_name='label',
272+
null=True,
273+
blank=True,
274+
on_delete=models.CASCADE,
275+
help_text='The project this label is associated with. If unset, this '
276+
'label is global to the instance',
277+
)
278+
279+
name = models.CharField(max_length=25, help_text='The label value.')
280+
description = models.TextField(
281+
null=True,
282+
blank=True,
283+
help_text='A description of what the label is and when it should be '
284+
'applied.',
285+
)
286+
color = ColorField(help_text='The color code to use in the UI.')
287+
288+
def __str__(self):
289+
return self.name
290+
291+
class Meta:
292+
ordering = ['name']
293+
unique_together = [('project', 'name')]
294+
295+
259296
class Tag(models.Model):
260297
name = models.CharField(max_length=20)
261298
pattern = models.CharField(
@@ -435,6 +472,7 @@ class SubmissionMixin(FilenameMixin, EmailMixin, models.Model):
435472
# submission metadata
436473

437474
name = models.CharField(max_length=255)
475+
labels = models.ManyToManyField(Label)
438476

439477
@cached_property
440478
def list_archive_url(self):
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
features:
3+
- |
4+
Add support for patch labels. Labels are a way to organize and prioritize
5+
submissions. You can apply labels to patches and cover letters to signify
6+
priority, category, or any other marker you wish.
7+
8+
Labels can be either global or tied to the project they are created in.
9+
Labels can have an optional description attached, which will provide a
10+
little insight into the purpose of the label. Labels are completely
11+
customizable and the labels available will vary by instance.

0 commit comments

Comments
 (0)