mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Converted internal link generation in the admin and admin document generator to use named URLs.
Thanks to Florian Apolloner for both the initial patch and his final push to get this fixed, to Dario Ocles for his great work on the admin templates and switching the admin_doc application to also use named URLs, to Mikko Hellsing for his comments and to Jannis and Julien for their review and design guidance. Fixes #15294. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16857 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7b21bfc074
commit
aaf77c1676
41 changed files with 488 additions and 104 deletions
50
tests/regressiontests/admin_custom_urls/models.py
Normal file
50
tests/regressiontests/admin_custom_urls/models.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
from functools import update_wrapper
|
||||
|
||||
from django.contrib import admin
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Action(models.Model):
|
||||
name = models.CharField(max_length=50, primary_key=True)
|
||||
description = models.CharField(max_length=70)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class ActionAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
A ModelAdmin for the Action model that changes the URL of the add_view
|
||||
to '<app name>/<model name>/!add/'
|
||||
The Action model has a CharField PK.
|
||||
"""
|
||||
|
||||
list_display = ('name', 'description')
|
||||
|
||||
def remove_url(self, name):
|
||||
"""
|
||||
Remove all entries named 'name' from the ModelAdmin instance URL
|
||||
patterns list
|
||||
"""
|
||||
return filter(lambda e: e.name != name, super(ActionAdmin, self).get_urls())
|
||||
|
||||
def get_urls(self):
|
||||
# Add the URL of our custom 'add_view' view to the front of the URLs
|
||||
# list. Remove the existing one(s) first
|
||||
from django.conf.urls.defaults import patterns, url
|
||||
|
||||
def wrap(view):
|
||||
def wrapper(*args, **kwargs):
|
||||
return self.admin_site.admin_view(view)(*args, **kwargs)
|
||||
return update_wrapper(wrapper, view)
|
||||
|
||||
info = self.model._meta.app_label, self.model._meta.module_name
|
||||
|
||||
view_name = '%s_%s_add' % info
|
||||
|
||||
return patterns('',
|
||||
url(r'^!add/$', wrap(self.add_view), name=view_name),
|
||||
) + self.remove_url(view_name)
|
||||
|
||||
|
||||
admin.site.register(Action, ActionAdmin)
|
Loading…
Add table
Add a link
Reference in a new issue