|
18 | 18 | from django.utils.functional import cached_property |
19 | 19 | from django.utils import timezone as tz_utils |
20 | 20 |
|
21 | | -from patchwork.fields import HashField |
| 21 | +from patchwork.fields import HashField, ColorField |
22 | 22 | from patchwork.hasher import hash_diff |
23 | 23 |
|
24 | 24 | if settings.ENABLE_REST_API: |
@@ -256,6 +256,43 @@ class Meta: |
256 | 256 | ordering = ['ordering'] |
257 | 257 |
|
258 | 258 |
|
| 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 | + |
259 | 296 | class Tag(models.Model): |
260 | 297 | name = models.CharField(max_length=20) |
261 | 298 | pattern = models.CharField( |
@@ -435,6 +472,7 @@ class SubmissionMixin(FilenameMixin, EmailMixin, models.Model): |
435 | 472 | # submission metadata |
436 | 473 |
|
437 | 474 | name = models.CharField(max_length=255) |
| 475 | + labels = models.ManyToManyField(Label) |
438 | 476 |
|
439 | 477 | @cached_property |
440 | 478 | def list_archive_url(self): |
|
0 commit comments