MarcS82
MarcS82

Reputation: 2517

How do I get a param inside an URL in django admin?

I use django admin and want to access the object id in an URL like this: http://localhost:8000/polls/platform/837/change

class PlatformAdmin(admin.ModelAdmin):
  def get_queryset(self, request):
    print(request.??)

So what should be returned is the 837

Upvotes: 0

Views: 159

Answers (1)

Higor Rossato
Higor Rossato

Reputation: 2046

ModelAdmin class has get_object method which receives object_id, so basically you need to override that method.

class PlatformAdmin(admin.ModelAdmin):
    def get_object(self, request, object_id, form_field=None):
        # print(object_id)
        return super().get_object(request, object_id, form_field=None)

Upvotes: 1

Related Questions