hourglass icon issue on django admin page for a table

I am getting an error for only one table on django admin panel.

We are using two managers.

  1. Default manager
  2. Custom manager

For admin panel, I have been using default manager to allow superusers to see archived data as well. That’s why we are using custom manger where i am excluding archived records from queryset.

I have debugged the admin view code and tried to intercept the request after hitting request from admin panel.

Admin view is successfully returning queryset. After that, I don’t know where it’s going actually.

I will share screenshots below, what’s the actual behaviour of request from admin panel.

  • It took around 30 seconds for processing:

    image

  • After that it got hourglass icon

    image

  • Then

    image

  • Finally

    image

Total duration to process the request was more than one minute. It’s quite awkward.

model

class CandidateAssessment(models.Model):
    candidate = models.ForeignKey(
        Candidate, on_delete=models.CASCADE, null=True, blank=True)
    assessment = models.ForeignKey(
        'Assessment.Assessment', on_delete=models.CASCADE, null=True, blank=True)
    report = models.ForeignKey(
        CandidateAssessmentReport, on_delete=models.CASCADE, null=True, blank=True
    )
    status = models.ForeignKey(
        CandidateAssessmentStatus, on_delete=models.CASCADE, null=True, blank=True)
    modify_at = models.DateTimeField(auto_now=True, null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True, null=True, blank=True)

    objects = CustomManager()
    all_objects = models.Manager()

    def __str__(self) -> str:
        return str(self.id)

    class Meta:
        verbose_name = 'Candidate Assessment'
        verbose_name_plural = 'Candidate Assessments'

admin

class CandidateAssessmentAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        return CandidateAssessment.all_objects.all()
    list_display = (
        'id', 'candidate', 'assessment', 'report',
        'status', 'modify_at', 'created_at',
    )
    search_fields = ['id', 'candidate__first_name', 'candidate__email',
                     'candidate__surname', 'assessment__name', 'status__name']

I have intercepted request on this line where I used debug-console to query with default manager. It returned all objects in micro seconds.

return CandidateAssessment.all_objects.all()

In my opinion, It’s stuck somewhere in processing HTML template because admin view is returning queryset simultaneously.

Thank you for reading!

I would prior solution suggestion. Please do contribute to fix this issue.

Welcome @Dr-Django !

This is an incorrect statement.

This return statement actually returns a queryset, which is not executed as a query until the contents of the queryset are referenced. As a result, Django refers to querysets as being lazy - see Querysets are lazy and When QuerySets are evaluated.

Depending upon the number of related objects from those FK fields, I’m guessing that the time is mostly being spent rendering all the option values in the drop-downs for the selects being generated for those FK fields. It may also be generating a very large web page that is taking a lot of time being rendered by your browser. You can get an idea of this by looking at the size of the page returned.

The Django Debug Toolbar would give you a much clearer picture as to where the time is being spent.

@KenWhitesell

Thanks for welcoming me!

You’re right! it was my mistake regarding the queryset statement. I used the changelist_view method in the admin view class to calculate the page size, which gave me this result:

Page size: 71256 bytes (69.59 KB)

Instead of using:

I plan to profile the admin view using django-silk. I’ll dig deeper into this and get back to you with my findings.