I would like to make a link that would take the user to a particular item in the admin site (assuming they have the correct permissions).
Something like: https://mysite/admin/app/model/id/
Can this be done with reverse?
If you open a Django project's urls.py file, in the urlpatterns variable you'll see the line path('admin/', admin. site. urls) . This last path definition tells Django to enable the admin site app on the /admin/ url directory (e.g. http://127.0.0.1:8000/admin/ ).
You can do that by using request. META['HTTP_REFERER'] , but it will exist if only your tab previous page was from your website, else there will be no HTTP_REFERER in META dict . So be careful and make sure that you are using . get() notation instead.
your company should follow a least access principle policy; so yes: only select people should have access. Django has basic auditing capability via signals and displayed in the admin out of the box. You can build on top of this.
Django admin allows access to users marked as is_staff=True . To disable a user from being able to access the admin, you should set is_staff=False . This holds true even if the user is a superuser. is_superuser=True .
You can get the url in the view, using reverse
,
object_change_url = reverse('admin:myapp_mymodel_change', args=(obj.id,))
Or in the template, using the url tag
{% url 'admin:myapp_mymodel_change' obj.id %}
or
{% load admin_urls %}
{% url opts|admin_urlname:'change' obj.id %}">
Note the above url tag syntax is for Django >= 1.5.
For more information, see the Django docs on reversing admin urls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With