Added view for chosen tags
This commit is contained in:
parent
bc50f118b8
commit
890d1004e1
|
|
@ -5,6 +5,14 @@ from configuration.models import TranslationSettings
|
|||
from utils.models import TJSONField, TranslatedFieldsMixin
|
||||
|
||||
|
||||
class TagQuerySet(models.QuerySet):
|
||||
def filter_chosen(self):
|
||||
return self.exclude(priority__isnull=True)
|
||||
|
||||
def order_by_priority(self):
|
||||
return self.order_by('priority')
|
||||
|
||||
|
||||
class Tag(TranslatedFieldsMixin, models.Model):
|
||||
"""Tag model."""
|
||||
|
||||
|
|
@ -16,6 +24,8 @@ class Tag(TranslatedFieldsMixin, models.Model):
|
|||
verbose_name=_('Category'))
|
||||
priority = models.IntegerField(unique=True, null=True, default=None)
|
||||
|
||||
objects = TagQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ app_name = 'tag'
|
|||
|
||||
router = SimpleRouter()
|
||||
router.register(r'categories', views.TagCategoryViewSet)
|
||||
router.register(r'chosen_tags', views.ChosenTagsView, basename='Tag')
|
||||
|
||||
urlpatterns = [
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,22 @@
|
|||
"""Tag views."""
|
||||
from rest_framework import viewsets, mixins, status
|
||||
from rest_framework import viewsets, mixins, status, generics
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from tag import filters, models, serializers
|
||||
from rest_framework import permissions
|
||||
|
||||
|
||||
class ChosenTagsView(generics.ListAPIView, viewsets.GenericViewSet):
|
||||
pagination_class = None
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
serializer_class = serializers.TagBaseSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
return models.Tag.objects\
|
||||
.filter_chosen() \
|
||||
.order_by_priority()
|
||||
|
||||
|
||||
# User`s views & viewsets
|
||||
class TagCategoryViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
|
||||
"""ViewSet for TagCategory model."""
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user