HI Consider this example and you may get the solution
Model name is Profile and in admin.py override this def get_form(self, request, obj=None, **kwargs): ------------------------------------------------------------- admin.py from django.contrib.auth.models import User class ProfileAdmin(admin.ModelAdmin): def get_form(self, request, obj=None, **kwargs): username = request.user.username # code to extract property print (username) if username == "dgp": #dgp is username self.exclude = ("CaseAdvocate","CaseActionTaken", ) # "CaseAdvocate","CaseActionTaken",are column names form = super(ProfileAdmin, self).get_form(request, obj, **kwargs) return form else: form = super(ProfileAdmin, self).get_form(request, obj, **kwargs) return form ------------------------------------------------ Replace dgp with your own username and write the query. Here i am excluding "CaseAdvocate","CaseActionTaken" Columns in display for "dgp" user and showing all colums to other user On Thu, May 23, 2019 at 6:08 AM Rounak Jain <rounakjai...@gmail.com> wrote: > 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 django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > 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 > <https://groups.google.com/d/msgid/django-users/CANNuxWPeGAgGEikRkoYgdp%3Dse9W0MBVxsLwac1W_BJw0%3DtmGOg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- *Mr. Shetty Balaji S.Asst. ProfessorDepartment of Information Technology,* *SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.India* *Official: bsshe...@sggs.ac.in <bsshe...@sggs.ac.in> * * Mobile: +91-9270696267* -- 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 django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. 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/CAECSbOvdAnRf3o_2qefcpET3bA03o7tQFzndEQrWV%3DjLA9h7zg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.