Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
Django query taking too much time

I'm using django and django rest framework to make a query from all users in data that have a permission sent as a url parameter but this query is taking too long.

I'm user pycharm debugger how can I try to check why is it taking to long, this is the function:

@list_route(url_path='permission/(?P<permission>.+)')
def read_permission(self, request, *args, **kwargs):
    serializer = self.get_serializer_class()
    qs = get_user_model().objects.filter_by_permission(self.kwargs.get('permission'))
    qs = qs.order_by(Lower('username'))
    return Response(serializer(qs, many=True).data)

Update

Adding the serializer

class UserSerializer(UserLabelMixin):
    user_permissions = serializers.SlugRelatedField(many=True, read_only=True, slug_field='codename')

    class Meta:
        model = get_user_model()
        fields = ['id', 'email', 'is_superuser', 'is_staff', 'label',
                  'full_name', 'first_name', 'last_name', 'username',
                  'teams', 'date_joined', 'last_login',
                  'user_permissions', 'groups', 'ui_preferences', 'internal_project',
                  'staff_id', 'oem_id', 'oem_email', 'oem_department', 'comment']
        read_only_fields = fields
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This may help you

get_user_model().objects.prefetch_related("user_permissions", "groups").filter_by_permission...
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!