I'm successfully using Wagtail's wagtail.contrib.modeladmin to make a regular Django model editable from the Wagtail admin. I'd like to hyperlink to the modeladmin "create" and "edit" views from my template. What is the URL "name" I can use to reference these views? There appears to be no urls module in wagtail.contrib.admin and no documentation on this.
Here's my directory app's models.py:
from django.db import models
class Organisation(models.Model):
title = models.CharField(max_length=255)
logo = models.ImageField(upload_to='logos', blank=True)
...
And my project's urls.py:
from django.conf.urls import include, url
urlpatterns = [
url(r'^admin/', include(wagtailadmin_urls)),
...
url(r'^directory/', include('directory.urls')),
]
The URL name will be of the following form, where [action] is one of index, create, edit, delete, inspect or choose_parent:
[app_label]_[model_name]_modeladmin_[action]
For example:
{% url 'directory_organisation_modeladmin_index' %}{% url 'directory_organisation_modeladmin_create' %}{% url 'directory_organisation_modeladmin_edit' instance_pk=37 %}{% url 'directory_organisation_modeladmin_delete' instance_pk=37 %}{% url 'directory_organisation_modeladmin_inspect' instance_pk=37 %}{% url 'directory_organisation_modeladmin_choose_parent' %}Since the URLConf provided doesn't contain a namespace argement to include(), no namespace is required.
Similar to Django's built-in Admin, Wagtail generates these URLs dynamically in the ModelAdmin.get_admin_urls_for_registration() with some helpers like AdminURLHelper.get_action_url_name().
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