from rest_framework import mixins,viewsets
from rest_framework import filters
from django_filters.rest_framework import DjangoFilterBackend
from .filters import XXX
from .serializers import XXX
from .models import XXX
class PhotoViews(viewsets.GenericViewSet, mixins.CreateModelMixin, mixins.DestroyModelMixin, mixins.ListModelMixin):
"""
XXX
"""
queryset = Photo.objects.all()
serializer_class = PhotoSerializers
filter_backends = (DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter,)
search_fields = ('CustomerId__Code',) # drf的
filter_class = PhotoFilter # django的
ordering_fields = ('Date',)
ordering = ('-Date',)
class PhotoSerializers(serializers.ModelSerializer):
# def create(self, validated_data):
# print(validated_data)
class Meta:
model = Photo
fields = ['Id', 'thumb', 'Kind']
# exclude = ['ContactsId',]
# fields = '__all__'
from django_filters import rest_framework as filters,
class PhotoFilter(filters.FilterSet):
class Meta:
model = HousePhoto
fields = ['Id', 'House_id']
drf viewset template
最新推荐文章于 2023-04-17 11:41:10 发布