Reputation:
like I created 3 events 1 is on 23rd, 2nd in on 21 and 3rd is on 24th then it should arrange the event as 21, 23 and 24
This is the serializers.py
class UpcomingEventsSerializer(serializers.ModelSerializer):
class Meta:
model = Events
fields = ('id', 'event_title',
'small_description', 'event_location', 'event_date')
This is the views.py
class UpcomingEventsAPIView(generics.GenericAPIView, mixins.ListModelMixin, mixins.CreateModelMixin,
mixins.UpdateModelMixin, mixins.RetrieveModelMixin,
mixins.DestroyModelMixin):
permission_classes = [permissions.AllowAny]
serializer_class = UpcomingEventsSerializer
queryset = Events.objects.all()
lookup_field = 'id'
filter_backends = [DjangoFilterBackend, filters.SearchFilter]
def get(self, request, id=None):
if id:
return self.retrieve(request)
else:
return self.list(request)
Upvotes: 0
Views: 36
Reputation: 4095
You can do:
queryset = Events.objects.order_by('-event_date')
Upvotes: 1