djangoã§ç¬èªã®èªè¨¼ã¤ãadminãã¼ã¸ã®è¿½å
調ã¹ã¦ããã»ã¨ãã©ModelããAdminãã¼ã¸ãä½ã話ã°ããã§ãå®å
¨ã«ã«ã¹ã¿ãã¤ãºããããã¼ã¸ã§ãèªè¨¼ã ãæµç¨ããããã¨ããç¨éã«ããã¦ã¯å
¨ç¶åèã«ãªãã³ã¼ãããªãã£ãã®ã§ãä¸å¿è¨é²ãã¦ããã
http://docs.djangoproject.jp/en/latest/ref/contrib/admin/index.html
ã®Adding views to admin sites辺ãã«ãã©ã£ã¨æ¸ãã¦ãããã ãã©ãããã ããããã url追å ããã ãã ã£ãã
https://github.com/django/django/blob/master/django/contrib/admin/sites.py
ã®get_urlsã®å®è£ ãè¦ãã°ããããã©ãå®éã®ãã¼ã¸ã®å¦çãããé¢æ°ã«å¯¾ãã¦èªè¨¼ãã¼ã¸ã®wrapperãããã¦ãã
wrapããé¢æ°èªä½ã¯ç´æ¥è§¦ããªãã®ã§ããããããªãããã³ãããã¦ã¿ãã
class MyAdmin(admin.AdminSite): def get_urls(self): def wrap(view, cacheable=False): def wrapper(*args, **kwargs): return self.admin_view(view, cacheable)(*args, **kwargs) return update_wrapper(wrapper, view) patterns = super(MyAdmin, self).get_urls() patterns += urls.patterns( '', urls.url(r'^edit/$', wrap(self.editPage), name='edit'), ) return patterns
urlpatternã®ç»é²ã¯ä»¥ä¸ã®ã¨ããã
adminSite = MyAdmin() urlpatterns = urls.patterns( '', urls.url(r'^admin/', urls.include(adminSite.urls)), )
ããã§ã/admin/edit/ãªã©ã®ãã¼ã¸ãéãã¨ãã¦ã¼ã¶åãèãããã«ãªãã
ãã³ãã¬ã¼ãå´ã¯ã
{% extends "admin/base_site.html" %} {% load i18n admin_static %} {% block content %} ... {% endblock content %}
ãããªæãã§è¦æ £ããadminãã¼ã¸ã®ãããã表示ãããã