October 24, 2024
Chicago 12, Melborne City, USA
python

Failed lookup for key [site_header] when extending admin/change_list.html


i tried to extend change_list.html template from using this two guide
https://hakibenita.com/how-to-turn-django-admin-into-a-lightweight-dashboard
&
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template
this is my view

@admin.register(summery)
class StaisticsSummery(ModelAdmin):
     change_list_template ="admin/stat_summary_change_list.html"
     def changelist_view(self, request,extra_context=None):
          extra_context = extra_context or {}
          filterUser = request.GET.get("q","")
          filterStart  = request.GET.get("startDate","")
          filterEnd  = request.GET.get("endDate","")
          if filterStart=="":
               filterStart = "1300-01-01"
          if filterEnd=="":
               filterEnd = "1500-12-29"
          result =  list(User.objects.values("username").annotate(
               total_Balance=Sum('statistics__balance',default=0,filter=Q(statistics__created_at__gte=filterStart)|Q(statistics__created_at__lte=filterEnd)),
...)
          ).order_by("username"))
          if(filterUser!="" and filterUser is not None):
               result =result.filter(username=filterUser)
          extra_context["result"]=result
          return  super().changelist_view(request,extra_context)

i request when there was’nt any start and end to querystring everything looks works fine and all result are valid
i use the given query in django shell an everything were valid but somehow opt context variable is changing when trying to query with dates via the browser
is there any better way to debug this problem related to context object



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video