feat/search #2
@@ -1,2 +1,3 @@
|
|||||||
from .core import * # noqa
|
from .core import * # noqa
|
||||||
from .user import * # noqa
|
from .user import * # noqa
|
||||||
|
from .others import * # noqa
|
||||||
|
|||||||
12
core/apps/accounts/admin/others.py
Normal file
12
core/apps/accounts/admin/others.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from unfold.admin import ModelAdmin
|
||||||
|
|
||||||
|
from core.apps.accounts.models import SearchHistory
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(SearchHistory)
|
||||||
|
class SearchHistoryAdmin(ModelAdmin):
|
||||||
|
list_display = (
|
||||||
|
"id",
|
||||||
|
"__str__",
|
||||||
|
)
|
||||||
0
core/apps/api/permissions/__init__.py
Normal file
0
core/apps/api/permissions/__init__.py
Normal file
@@ -1 +1,2 @@
|
|||||||
from .category import * # noqa
|
from .category import * # noqa
|
||||||
|
from .search import * # noqa
|
||||||
|
|||||||
1
core/apps/api/serializers/search/__init__.py
Normal file
1
core/apps/api/serializers/search/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .search import * # noqa
|
||||||
27
core/apps/api/serializers/search/search.py
Normal file
27
core/apps/api/serializers/search/search.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
from core.apps.accounts.models import SearchHistory
|
||||||
|
|
||||||
|
|
||||||
|
class BaseSearchHistorySerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = SearchHistory
|
||||||
|
fields = [
|
||||||
|
"value",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ListSearchHistorySerializer(BaseSearchHistorySerializer):
|
||||||
|
class Meta(BaseSearchHistorySerializer.Meta): ...
|
||||||
|
|
||||||
|
|
||||||
|
class RetrieveSearchHistorySerializer(BaseSearchHistorySerializer):
|
||||||
|
class Meta(BaseSearchHistorySerializer.Meta): ...
|
||||||
|
|
||||||
|
|
||||||
|
class CreateSearchHistorySerializer(BaseSearchHistorySerializer):
|
||||||
|
class Meta(BaseSearchHistorySerializer.Meta): ...
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
validated_data['user'] = self.context['request'].user
|
||||||
|
history = SearchHistory.objects.create(**validated_data)
|
||||||
|
return history
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from rest_framework.routers import DefaultRouter
|
from rest_framework.routers import DefaultRouter
|
||||||
|
|
||||||
from core.apps.api.views import CategoryViewSet
|
from core.apps.api.views import CategoryViewSet, SearchHistoryViewSet
|
||||||
|
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
router.register("category", CategoryViewSet, basename="category")
|
router.register("category", CategoryViewSet, basename="category")
|
||||||
|
router.register("search-history", SearchHistoryViewSet, basename="search-history")
|
||||||
urlpatterns = [path("", include(router.urls))]
|
urlpatterns = [path("", include(router.urls))]
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
from .category import * # noqa
|
from .category import * # noqa
|
||||||
|
from .search import * # noqa
|
||||||
|
|||||||
1
core/apps/api/views/search/__init__.py
Normal file
1
core/apps/api/views/search/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .search import * # noqa
|
||||||
29
core/apps/api/views/search/search.py
Normal file
29
core/apps/api/views/search/search.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
from rest_framework import mixins
|
||||||
|
from rest_framework.viewsets import GenericViewSet
|
||||||
|
from django_core.mixins.base import BaseViewSetMixin
|
||||||
|
from drf_spectacular.utils import extend_schema
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
from core.apps.accounts.models import SearchHistory
|
||||||
|
from core.apps.api.serializers.search import (
|
||||||
|
ListSearchHistorySerializer,
|
||||||
|
RetrieveSearchHistorySerializer,
|
||||||
|
CreateSearchHistorySerializer,
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@extend_schema(tags=['Search'])
|
||||||
|
class SearchHistoryViewSet(BaseViewSetMixin, mixins.ListModelMixin, mixins.CreateModelMixin,
|
||||||
|
mixins.DestroyModelMixin, GenericViewSet):
|
||||||
|
serializer_class = ListSearchHistorySerializer
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
http_method_names = ['get', 'post', 'delete']
|
||||||
|
action_permission_classes = {}
|
||||||
|
action_serializer_class = {
|
||||||
|
'list': ListSearchHistorySerializer,
|
||||||
|
'create': CreateSearchHistorySerializer,
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
queryset = SearchHistory.objects.filter(user=self.request.user)
|
||||||
|
return queryset
|
||||||
Reference in New Issue
Block a user