A
A
Alexander2016-05-03 12:10:09
Django
Alexander, 2016-05-03 12:10:09

How to get current url in admin.py?

admin.py

....
from django.http.request import HttpRequest
....
class ProductAdmin(TranslatableAdmin):
....
    list_display = ("title", "category", "_stat", "_actions")
.......
    def _actions(self, obj):
        print(HttpRequest.META['HTTP_HOST'])
        return """
        <a href="{}" class="btn btn-primary"><i class="fa fa-pencil"></i></a>
        <a href="#" name="delete_item" id="20" data-toggle="modal" data-target="#deleteModel" class="btn btn-danger"><i class="fa fa-trash"></i></a>
        """.format()

error: AttributeError: type object 'HttpRequest' has no attribute 'META'
how to get full current url in admin.py ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-05-03
@sim3x

https://docs.djangoproject.com/en/1.9/ref/request-...
self.request.path should contain what you think (not really necessary) what you need
Actually you need to learn https://docs.djangoproject.com/en/dev/ref/contrib/...
name=delete_item - better to make it a button - if it is ajaxed (don't forget to check user rights before deleting!)
id - need to be done with your own prefix, so as not to interfere with the main admin panel, in general, everything you do in the admin panel should have your prefix

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question