<?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>Ben Jao Ming &#187; Django</title>
	<atom:link href="http://overtag.dk/wordpress/category/computers/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://overtag.dk/wordpress</link>
	<description>101% objective... always</description>
	<lastBuildDate>Fri, 02 Apr 2010 23:50:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9-rare</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Changing the Django Admin site title</title>
		<link>http://overtag.dk/wordpress/2010/04/changing-the-django-admin-site-title/</link>
		<comments>http://overtag.dk/wordpress/2010/04/changing-the-django-admin-site-title/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 23:45:52 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[django-admin]]></category>
		<category><![CDATA[translation]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=191</guid>
		<description><![CDATA[Often the Django Admin should look a little different for the sake of your users or for the sake of yourself (running multiple django sites with identical looks and titles can be such a pain). Often users don&#8217;t know what Django is, and it takes ages to explain, and even after that they have no [...]]]></description>
			<content:encoded><![CDATA[<p>Often the Django Admin should look a little different for the sake of your users or for the sake of yourself (running multiple django sites with identical looks and titles can be such a pain). Often users don&#8217;t know what Django is, and it takes ages to explain, and even after that they have no clue. Also, often my administration has nothing to do with a website, so I don&#8217;t want the text &#8220;Site administration&#8221;.</p>
<p>First of all, you wanna add <strong>templates/admin/base_site.html</strong> to your project. This file can safely be overwritten, since it&#8217;s a file that the django devs have intended for the exact purpose of customizing your admin site a bit. Here&#8217;s an example of what to put in the file:</p>

<div class="wp_syntax"><div class="code"><pre>{% extends &quot;admin/base.html&quot; %}
{% load i18n %}
&nbsp;
{% block title %}{{ title }} <PIPE> {% trans 'Some Organisation' %}{% endblock %}
&nbsp;
{% block branding %}
&lt;style type=&quot;text/css&quot;&gt;
  #header
  {
    /* your style here */
  }
&lt;/style&gt;
&lt;h1 id=&quot;site-name&quot;&gt;{% trans 'Organisation Website' %}&lt;/h1&gt;
{% endblock %}
&nbsp;
{% block nav-global %}{% endblock %}</pre></div></div>

<p>This is common practice. But I noticed after this that I was still left with an annoying &#8220;Site Administration&#8221; on the main admin index page. And this string was not inside any of the template, but rather set inside the admin view. Luckily it&#8217;s quite easy to change. Assuming your language is set to English, run the following commands from your project directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> locale
$ .<span style="color: #000000; font-weight: bold;">/</span>manage.py makemessages -l en</pre></div></div>

<p>Now open up the file <strong>locale/en/LC_MESSAGES/django.po</strong> and add two lines after the header information (the last two lines of this example)</p>

<div class="wp_syntax"><div class="code"><pre class="gettext"><span style="color: #ff0000;">&quot;Project-Id-Version: PACKAGE VERSION<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Report-Msgid-Bugs-To: <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;POT-Creation-Date: 2010-04-03 03:25+0200<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Last-Translator: FULL NAME &lt;EMAIL@ADDRESS&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Language-Team: LANGUAGE &lt;LL@li.org&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;MIME-Version: 1.0<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Content-Type: text/plain; charset=UTF-8<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff0000;">&quot;Content-Transfer-Encoding: 8bit<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">msgid</span> <span style="color: #ff0000;">&quot;Site administration&quot;</span>
<span style="color: #000000; font-weight: bold;">msgstr</span> <span style="color: #ff0000;">&quot;Main administration index&quot;</span></pre></div></div>

<p>After this, remember to run this and reload your project&#8217;s server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ .<span style="color: #000000; font-weight: bold;">/</span>manage.py compilemessages</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2010/04/changing-the-django-admin-site-title/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django tip: Automatic logins</title>
		<link>http://overtag.dk/wordpress/2010/02/django-tip-automatic-logins/</link>
		<comments>http://overtag.dk/wordpress/2010/02/django-tip-automatic-logins/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 13:21:56 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[authenticate]]></category>
		<category><![CDATA[login]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=182</guid>
		<description><![CDATA[In the Django documentation we see the following:
When you&#8217;re manually logging a user in, you must call authenticate() before you call login().
That&#8217;s all really nice, because it makes sure that all your authentication backends are tried out; but if you want a really quick remedy for getting the job done, then you&#8217;ll need to set [...]]]></description>
			<content:encoded><![CDATA[<p>In the Django documentation we see the following:</p>
<blockquote><p>When you&#8217;re manually logging a user in, you must call <strong>authenticate()</strong> before you call<strong> login()</strong>.</p></blockquote>
<p>That&#8217;s all really nice, because it makes sure that all your authentication backends are tried out; but if you want a really quick remedy for getting the job done, then you&#8217;ll need to set the <em>user.backend</em> property to the specific backend that authenticated the user. Beware that the Django developers can change these requirements. I wanted this to avoid writing my own backend, so I did this to log users in via a special view accepting a hash from the URL (from an e-mail that had a link that&#8217;d automatically log a user in). This could also become useful if you want to <em>become</em> a different user.</p>

<div class="wp_syntax"><div class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">def</span> get_hash<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">import</span> hashlib
    m = hashlib.<span style="color: #dc143c;">md5</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    m.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span> + settings.<span style="color: black;">LOGIN_SECRET</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>m.<span style="color: black;">hexdigest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> auto_login<span style="color: black;">&#40;</span>request, user_id, secret<span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #dc143c;">user</span> = get_object_or_404<span style="color: black;">&#40;</span>User, <span style="color: #008000;">id</span>=user_id<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> secret == get_hash<span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>user_id<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">raise</span> Http404<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #dc143c;">user</span>.<span style="color: black;">backend</span> = <span style="color: #483d8b;">&quot;django.contrib.auth.backends.ModelBackend&quot;</span>
    login<span style="color: black;">&#40;</span>request, <span style="color: #dc143c;">user</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> HttpResponseRedirect<span style="color: black;">&#40;</span>reverse<span style="color: black;">&#40;</span><span style="color: #483d8b;">'frontpage'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p><strong>BEWARE!</strong><br />
I strongly suggest that you don&#8217;t log any superusers in this way. You could add a conditional statement <em>not user.is_superuser</em> or similar.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2010/02/django-tip-automatic-logins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django localized date template filter</title>
		<link>http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/</link>
		<comments>http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 22:24:13 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[template filter]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=155</guid>
		<description><![CDATA[UPDATE! This is going to be redundant in Django 1.2, in which you can add DATE_FORMAT to your django.po files.
I&#8217;ve often been frustrated that using settings.DATE_FORMAT does not give a localized date. Granted that the name of a month may be localized, but the format string does not change. So let&#8217;s start out by modifying [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE!</strong> This is going to be redundant in Django 1.2, in which you can add DATE_FORMAT to your django.po files.</p>
<p>I&#8217;ve often been frustrated that using <strong>settings.DATE_FORMAT</strong> does not give a localized date. Granted that the name of a month may be localized, but the format string does not change. So let&#8217;s start out by modifying <strong>settings.py</strong>. We wrap our default date format in a <b>ugettext</b> so the makemessages command will detect it, and we need to make it a dummy function, because the i18n library cannot be imported in settings.py due to circularity (it depends on settings.py).</p>

<div class="wp_syntax"><div class="code"><pre class="python">ugettext = <span style="color: #ff7700;font-weight:bold;">lambda</span> s: s
DATE_FORMAT = ugettext<span style="color: black;">&#40;</span><span style="color: #483d8b;">'N j, Y'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Run compilemessages and type in your localized date formats. Now we need a template filter that uses a localized format for calling the Django date format function. This is really simple:</p>

<div class="wp_syntax"><div class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">template</span>.<span style="color: black;">defaultfilters</span> <span style="color: #ff7700;font-weight:bold;">import</span> stringfilter
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span> <span style="color: #ff7700;font-weight:bold;">import</span> dateformat
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span>.<span style="color: black;">translation</span> <span style="color: #ff7700;font-weight:bold;">import</span> ugettext
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span> <span style="color: #ff7700;font-weight:bold;">import</span> settings
&nbsp;
@register.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> localdate<span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;Format date with localized date format&quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
    format = ugettext<span style="color: black;">&#40;</span>settings.<span style="color: black;">DATE_FORMAT</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> dateformat.<span style="color: black;">format</span><span style="color: black;">&#40;</span>value, format<span style="color: black;">&#41;</span></pre></div></div>

<p>And done. Using the filter is straight forward:</p>
<p><code><br />
Date: {{ my_date|localdate }}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/07/django-localized-date-template-filter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Presenting: django-simple-wiki</title>
		<link>http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/</link>
		<comments>http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 23:52:57 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[django application]]></category>
		<category><![CDATA[django-simple-wiki]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=142</guid>
		<description><![CDATA[It was bothering me that all the wikis I tried, all had either errors, feature lacks, too many dependencies or were simply unmaintained. So I decided to create yet another one. Curiously, the third hit when googling &#8216;django wiki&#8217; is Create a wiki in 20 minutes. Luckily that&#8217;s not really true, so all the PHP [...]]]></description>
			<content:encoded><![CDATA[<p>It was bothering me that all the wikis I tried, all had either errors, feature lacks, too many dependencies or were simply unmaintained. So I decided to create yet another one. Curiously, the third hit when googling &#8216;django wiki&#8217; is <a href="http://showmedo.com/videotutorials/video?name=1100000">Create a wiki in 20 minutes</a>. Luckily that&#8217;s not really true, so all the PHP guys and MediaWiki can continue breathing. This took me several days.</p>
<blockquote style="font-size: 150%;"><p><strong><a href="http://code.google.com/p/django-simple-wiki/">Google Code project page</a></strong></p></blockquote>
<blockquote style="font-size: 150%;"><p><strong><a href="http://wikidemo.overtag.dk/">Demo website</a></strong></p></blockquote>
<p><strong>Hierarchy and relations</strong><br />
First of all, as in the Trac wiki system, I chose to create a system for hierarchy, meaning that it&#8217;s possible to create an article and then create sub-articles. The hierarchy does not support multiple inheritance, because it needs to be basis for the permission system. That&#8217;s where the relation system comes in place: All articles can contain symmetrical relations to any other articles in the hierarchy.</p>
<p><strong>Parsing</strong><br />
Python and Django supports Markdown pretty much out of the box, so it&#8217;s an obvious choice to use this for parsing. The HTML features of normal Markdown have been removed, so all HTML is escaped in django-simple-wiki. And parsing is static, so every time a revision is created, the contents are passed and stored. This means that the contents of the article itself are not supposed to be dynamic. On the other hand, it is desirable to avoid parsing contents for every page hit. The parsing area of the application is only a few lines of code, and can be expanded if further parsing needs to be done, or someone wants to replace Markdown completely. For instance, if no parsing is done and HTML escaping is disabled, the wiki becomes a very simple CMS.</p>
<p><strong>Curious issues</strong><br />
There are a few out standing problems:</p>
<ul>
<li>Permission system is related to User entries in the Django auth system. But maybe this is too much of an annoyance, if the project already has groups setup in the existing auth system. On the other hand, other users would be bothered to setup both wiki groups and user groups, if the permission system was linked to user groups. And directly linking articles to user groups would require wiki-related groups to be created directly in the auth system.</li>
<li>Since relations are symmetrical, what should happen if one article is locked, but a user modifies it&#8217;s relations by deleting them from related articles?</li>
<li>Title editing: The title can only be created once, since it is coupled to the &#8217;slug&#8217; of the article. A user can deliberately create a completely different title, which is fine, but should subsequent editing be allowed, which would add complexity to the revision system?</li>
<li>Article deletion: When an article is deleted from the backend it shouldn&#8217;t worry anyone. But if the feature is added to the frontend, we would want to handle maliciousness etc. But should we really store all these files and revisions? Should we alert admins, so they can do the final cleanup?</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2009/04/presenting-django-simple-wiki/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django tip: Translating your application names (app_label)</title>
		<link>http://overtag.dk/wordpress/2008/07/django-tip-translating-your-application-names-app_label/</link>
		<comments>http://overtag.dk/wordpress/2008/07/django-tip-translating-your-application-names-app_label/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 21:03:57 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[gettext]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[makemessages]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=61</guid>
		<description><![CDATA[This MUST be a common issue for international developers: We use some geeky English name for our application and afterwards find that the translated admin index looks a little silly in the eyes of our native speaking users. Apparently a patch has been accepted in the Django dev version, but it&#8217;s not yet in the [...]]]></description>
			<content:encoded><![CDATA[<p>This MUST be a common issue for international developers: We use some geeky English name for our application and afterwards find that the translated admin index looks a little silly in the eyes of our native speaking users. Apparently <a href="http://code.djangoproject.com/ticket/1668">a patch</a> has been accepted in the Django dev version, but it&#8217;s not yet in the trunk. Here&#8217;s what to do: In your applications&#8217; <em>__init__.py</em> files put:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span>.<span style="color: black;">translation</span> <span style="color: #ff7700;font-weight:bold;">import</span> gettext_noop
gettext_noop<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;AppName&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>When your run <strong>manage.py makemessages -a</strong> there will be entries for these. Make sure to remove lines saying <em>#, fuzzy</em>. Now all you have to do is to customize the default admin template called <em>index.html</em> so it will actually do the translation of the application names.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>18
</pre></td><td class="code"><pre>        &lt;caption&gt;{% trans app.name %}&lt;/caption&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2008/07/django-tip-translating-your-application-names-app_label/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Django auto-translation of field values</title>
		<link>http://overtag.dk/wordpress/2008/07/django-auto-translation-of-field-values/</link>
		<comments>http://overtag.dk/wordpress/2008/07/django-auto-translation-of-field-values/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 22:04:26 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[gettext]]></category>
		<category><![CDATA[models]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=59</guid>
		<description><![CDATA[What&#8217;s really nice in Django is the gettext implementation and the _ convention. But when running django-admin.py makemessages we&#8217;re not generating any translations for dynamic values such as field values. So let&#8217;s say that we have a model and we&#8217;d like what&#8217;s in it to be displayed in a translated manner. In the new Django [...]]]></description>
			<content:encoded><![CDATA[<p>What&#8217;s really nice in Django is the gettext implementation and the _ convention. But when running <em>django-admin.py makemessages</em> we&#8217;re not generating any translations for dynamic values such as field values. So let&#8217;s say that we have a model and we&#8217;d like what&#8217;s in it to be displayed in a translated manner. In the new Django development version we&#8217;re able to create our own special field types. And we can extend the CharField to provide automatic translation:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">db</span> <span style="color: #ff7700;font-weight:bold;">import</span> models
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">utils</span>.<span style="color: black;">translation</span> <span style="color: #ff7700;font-weight:bold;">import</span> gettext_lazy as _
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> AutoTranslateField<span style="color: black;">&#40;</span>models.<span style="color: black;">CharField</span><span style="color: black;">&#41;</span>:
    <span style="color: #0000cd;">__metaclass__</span> = models.<span style="color: black;">SubfieldBase</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> to_python<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, value<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>_<span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>After that we just add whatever translations we know of to our <em>locale/CODE/LC_MESSAGES/django.po</em> file and run <em>compilemessages</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2008/07/django-auto-translation-of-field-values/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tip: Extending Django flatpages</title>
		<link>http://overtag.dk/wordpress/2008/07/tip-extending-django-flatpages/</link>
		<comments>http://overtag.dk/wordpress/2008/07/tip-extending-django-flatpages/#comments</comments>
		<pubDate>Sat, 12 Jul 2008 22:59:28 +0000</pubDate>
		<dc:creator>benjamin</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://overtag.dk/wordpress/?p=53</guid>
		<description><![CDATA[I did a Google search and since nothing came up, I&#8217;m writing this little tip on creating your own CMS by extending Django&#8217;s flatpages. What&#8217;s good about flatpages is that they&#8217;re included in Django and has some basic code to get you started. But clearly they&#8217;re not enough if you want other people to administer [...]]]></description>
			<content:encoded><![CDATA[<p>I did a Google search and since nothing came up, I&#8217;m writing this little tip on creating your own CMS by extending Django&#8217;s flatpages. What&#8217;s good about flatpages is that they&#8217;re included in Django and has some basic code to get you started. But clearly they&#8217;re not enough if you want other people to administer a site.. you&#8217;ll want to add extra fields and special help texts for the admin. But we still don&#8217;t want to rewrite those ~150 lines of code, and they can really help you get past all the boring stuff and into the action.</p>
<p>Simply do the following:</p>
<blockquote><p>
cp -R /usr/share/python-support/python-django/django/contrib/flatpages my_project/my_flatpages
</p></blockquote>
<p><i>views.py</i></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">from</span> my_project.<span style="color: black;">my_flatpages</span>.<span style="color: black;">models</span> <span style="color: #ff7700;font-weight:bold;">import</span> FlatPage</pre></td></tr></table></div>

<p><i>middleware.py</i></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">from</span> my_project.<span style="color: black;">my_flatpages</span>.<span style="color: black;">views</span> <span style="color: #ff7700;font-weight:bold;">import</span> flatpage</pre></td></tr></table></div>

<p><i>urls.py</i></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>3
4
5
</pre></td><td class="code"><pre class="python">urlpatterns = patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">'my_project.my_flatpages.views'</span>,
    <span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^(?P&lt;url&gt;.*)$'</span>, <span style="color: #483d8b;">'flatpage'</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p><em>my_project.my_flatpages.middleware.FlatpageFallbackMiddleware</em> has to be added to your <strong>MIDDLEWARE_CLASSES</strong> and <em>my_project.my_flatpages</em> to your <strong>INSTALLED_APPS</strong> and you&#8217;ll need to run <em>manage.py syncdb</em>, possibly changing the table name in <em>models.py</em>, so it doesn&#8217;t conflict with the old flatpages table. That&#8217;s basically it. After that you can work on the templates as described in the other howto&#8217;s, but now you have your own model to extend.</p>
]]></content:encoded>
			<wfw:commentRss>http://overtag.dk/wordpress/2008/07/tip-extending-django-flatpages/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
