I am new to Django. Below code returns objects created by the logged in
user. If the user's role property has value 'super', then I want all the
objects to be shown. If the user's role property is 'inter', then I want to
show all objects except objects created by 'super'. Where is the right
place to do this conditional querying?
Thanks

#views.py

class TaskViewSet(ModelViewSet):
    serializer_class = TaskSerializer
    def get_queryset(self):
        return Task.objects.all().filter(created_by=self.request.user)
    def perform_create(self, serializer):
        serializer.save(created_by=self.request.user)

#serializers.py

class TaskSerializer(ModelSerializer):

    class Meta:
        model = Task
        fields = ('id', 'name', 'status', 'created_by')

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANNuxWPeGAgGEikRkoYgdp%3Dse9W0MBVxsLwac1W_BJw0%3DtmGOg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to