<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Death of a Gremmie &#187; admin</title>
	<atom:link href="http://deathofagremmie.com/tag/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://deathofagremmie.com</link>
	<description>by Brian Neal</description>
	<lastBuildDate>Wed, 14 Jul 2010 02:31:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Custom Admin View Gotcha in Django 1.1</title>
		<link>http://deathofagremmie.com/2009/03/05/custom-admin-view-gotcha-django/</link>
		<comments>http://deathofagremmie.com/2009/03/05/custom-admin-view-gotcha-django/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 02:39:09 +0000</pubDate>
		<dc:creator>gremmie</dc:creator>
				<category><![CDATA[SG101 2.0]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://deathofagremmie.com/?p=184</guid>
		<description><![CDATA[I ran into something that took a few hours to sort out, so I thought I would write it up here in case it would help some other poor dope out. My goal is to create a custom admin view. I noticed that the Django docs had been updated recently, documenting a new member function [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into something that took a few hours to sort out, so I thought I would write it up here in case it would help some other poor dope out.</p>
<p>My goal is to create a custom admin view. I noticed that the Django docs had been updated recently, documenting a new member function called <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#get-urls-self">get_urls() on the ModelAdmin class</a>. The docs are kind of sketchy right now, but I gathered that this was the new way to add custom admin views for a model. However, before you can use this new feature, you have to cut over to the new scheme of hooking the contrib.admin site into your project. This is what took me a few hours to figure out, as I hadn&#8217;t noticed this change in the docs.</p>
<p>This is how I had my URLConf in my Django 1.0 project:</p>
<pre class="brush: python">
urlpatterns = patterns(&#039;&#039;,
(r&#039;^admin/(.*)&#039;, admin.site.root),
# ...
</pre>
<p>After updating my working copy of Django trunk, this is what my URLConf needed to look like to use the new admin get_urls() scheme:</p>
<pre class="brush: python">
urlpatterns = patterns(&#039;&#039;,
(r&#039;^admin/&#039;, include(admin.site.urls)),
# ...
</pre>
<p>All the changes are on line 2. Notice, there are <strong>two changes</strong> you have to make:</p>
<ol>
<li>The admin.site.root function is deprecated. You should now use <strong>include(admin.site.urls)</strong>.</li>
<li>The regular expression has changed subtly. Notice that the capturing of the part of the URL after &#8216;admin/&#8217; is no longer needed. I didn&#8217;t notice this right away, and trust me, it does weird things if you leave it in. <img src='http://deathofagremmie.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ol>
<p>After finally figuring these two things out, I am happy to report that the get_urls() function on my ModelAdmin class worked as I expected. For example, if I use the regular expression &#8216;^my_view/$&#8217; for my custom admin view, the view will be located at /admin/appname/modelname/my_view. This isn&#8217;t quite made crystal clear in the Django docs.</p>
<p>Now I am poised to add a custom admin view on my Google Calendar application. Stay tuned for more on that.</p>
]]></content:encoded>
			<wfw:commentRss>http://deathofagremmie.com/2009/03/05/custom-admin-view-gotcha-django/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
