Skip to content

Instantly share code, notes, and snippets.

@marteinn
Created February 25, 2025 06:02
Show Gist options
  • Save marteinn/8c96df9c5bc3ea61eead370cd3a2158c to your computer and use it in GitHub Desktop.
Save marteinn/8c96df9c5bc3ea61eead370cd3a2158c to your computer and use it in GitHub Desktop.
How to debug a ModelAdmin view in Django
from django.contrib import admin
from django.contrib.admin.options import ModelAdmin
from django.db import connection
class MockRequest:
pass
class MockSuperUser:
def has_perm(self, perm, obj=None):
return True
request = MockRequest()
request.user = MockSuperUser()
from myapp.models import MyModel
my_model = MyModel.objects.first()
modal_admin = ModelAdmin(UserVerificationProxy, admin.site)
print(ma.get_fields(request, my_model))
form = modal_admin.get_form(request, my_model)()
print(form)
print(connection.queries)
import pdb
pdb.set_trace()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment