2023-12-05 03:16:34 +00:00
|
|
|
from django.contrib.contenttypes.fields import GenericRelation
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
from .models import LabeledResource
|
|
|
|
|
|
|
|
__all__ = ['LabeledMixin']
|
|
|
|
|
|
|
|
|
|
|
|
class LabeledMixin(models.Model):
|
2023-12-19 10:42:44 +00:00
|
|
|
_labels = GenericRelation(LabeledResource, object_id_field='res_id', content_type_field='res_type')
|
2023-12-05 03:16:34 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
2023-12-19 10:42:44 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def labels(self):
|
|
|
|
return self._labels
|
|
|
|
|
|
|
|
@labels.setter
|
|
|
|
def labels(self, value):
|
|
|
|
self._labels.set(value, bulk=False)
|