taggedItem.py 670 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
from backend.models.my_model import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
Florent Chehab's avatar
Florent Chehab committed
3
from .tag import Tag
4
from .tagged_item_validation import tagged_item_validation
Florent Chehab's avatar
Florent Chehab committed
5 6


7
class TaggedItem(MyModelVersionned):
Florent Chehab's avatar
Florent Chehab committed
8 9 10 11 12 13
    tag = models.ForeignKey(Tag, related_name='+', on_delete=models.PROTECT)

    class Meta:
        abstract = True


14
class TaggedItemSerializer(MyModelVersionnedSerializer):
15 16

    def validate(self, attrs):
17 18
        tagged_item_validation(attrs)
        return attrs
Florent Chehab's avatar
Florent Chehab committed
19 20


21
class TaggedItemViewSet(MyModelVersionnedViewSet):
22 23
    def extend_queryset(self):
        return self.mymodel_queryset.prefetch_related('tag')