<?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>Django Days &#187; Tips</title>
	<atom:link href="http://djangodays.com/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://djangodays.com</link>
	<description>A growing collection of all things Django</description>
	<lastBuildDate>Tue, 20 Apr 2010 05:58:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WYSIWYG editor in Django Admin</title>
		<link>http://djangodays.com/2009/05/14/wysiwyg-editor-in-django-admin/</link>
		<comments>http://djangodays.com/2009/05/14/wysiwyg-editor-in-django-admin/#comments</comments>
		<pubDate>Thu, 14 May 2009 11:02:57 +0000</pubDate>
		<dc:creator>Joost</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Django Admin]]></category>
		<category><![CDATA[wysiwyg]]></category>

		<guid isPermaLink="false">http://djangodays.com/?p=107</guid>
		<description><![CDATA[As awesome as the standard Django admin might be, sometimes you want the textfields to have a little bit more functionality. This is quite simple to achieve. We&#8217;ll use WYMeditor in this case, but it should be equally easy with TinyMCE, FCKeditor or any other WYSIWYG editor out there.

First download jQuery and put it in [...]]]></description>
			<content:encoded><![CDATA[<p>As awesome as the standard Django admin might be, sometimes you want the textfields to have a little bit more functionality. This is quite simple to achieve. We&#8217;ll use <a href="http://www.wymeditor.org/" target="_blank">WYMeditor</a> in this case, but it should be equally easy with <a href="http://tinymce.moxiecode.com/" target="_blank">TinyMCE</a>, <a href="http://www.fckeditor.net/" target="_blank">FCKeditor</a> or any other <a href="http://www.google.com/search?q=javascript+WYSIWYG+editors" target="_blank">WYSIWYG editor out there</a>.</p>
<ol>
<li>First download <a href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2.min.js" target="_blank">jQuery</a> and put it in your MEDIA_ROOT or use Google&#8217;s AJAX  Libraries API:<code>http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js</code></li>
<li>Next, download WYMeditor and put it in your MEDIA_ROOT</li>
<li>Create a JavaScript file &#8220;fancyedit.js&#8221; with the following Javascript code:<code>// fancyedit.js<br />
$(document).ready(function() {<br />
&nbsp;&nbsp;$("#id_FIELDNAME").wymeditor({ // "FIELDNAME" is the name of the field you want to give the wysiwyg features<br />
&nbsp;&nbsp;&nbsp;&nbsp;updateSelector: "input:submit",<br />
&nbsp;&nbsp;&nbsp;&nbsp;updateEvent: "click"<br />
&nbsp;&nbsp;});<br />
});</code></li>
<li>Now we have to make sure that the correct JavaScript is loaded when a model has a rich text editor field:<code>import settings<br />
media = settings.MEDIA_URL<br />
class FooAdmin(admin.ModelAdmin):<br />
&nbsp;&nbsp;class Media:<br />
&nbsp;&nbsp;&nbsp;&nbsp;js = ('http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js', media+'/js/wymeditor/jquery.wymeditor.js', media+'/js/editor.js')</code></li>
</ol>
<p>That should be it!</p>
]]></content:encoded>
			<wfw:commentRss>http://djangodays.com/2009/05/14/wysiwyg-editor-in-django-admin/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Django foreign key default value example</title>
		<link>http://djangodays.com/2009/05/11/django-foreign-key-default-value-example/</link>
		<comments>http://djangodays.com/2009/05/11/django-foreign-key-default-value-example/#comments</comments>
		<pubDate>Mon, 11 May 2009 19:06:24 +0000</pubDate>
		<dc:creator>Joost</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[code examples]]></category>

		<guid isPermaLink="false">http://djangodays.com/?p=97</guid>
		<description><![CDATA[Here&#8217;s an example of how to set a default value for a models.ForeignKey field:
class Foo(models.Model):
&#160;&#160;&#160;&#160;a = models.CharField(max_length=10)
def get_foo():
&#160;&#160;&#160;&#160;return Foo.objects.get(id=1)
class Bar(models.Model):
&#160;&#160;&#160;&#160;b = models.CharField(max_length=10)
&#160;&#160;&#160;&#160;a = models.ForeignKey(Foo, default=get_foo)
Hope this helps someone (I&#8217;ve been looking for this quite some time&#8230;). If anyone know a better/neater way, please let us know in the comments!!
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an example of how to set a default value for a models.ForeignKey field:</p>
<p><code>class Foo(models.Model):<br />
&nbsp;&nbsp;&nbsp;&nbsp;a = models.CharField(max_length=10)<br />
<br/>def get_foo():<br />
&nbsp;&nbsp;&nbsp;&nbsp;return Foo.objects.get(id=1)<br />
<br/>class Bar(models.Model):<br />
&nbsp;&nbsp;&nbsp;&nbsp;b = models.CharField(max_length=10)<br />
&nbsp;&nbsp;&nbsp;&nbsp;a = models.ForeignKey(Foo, default=get_foo)</code></p>
<p>Hope this helps someone (I&#8217;ve been looking for this quite some time&#8230;). If anyone know a better/neater way, please let us know in the comments!!</p>
]]></content:encoded>
			<wfw:commentRss>http://djangodays.com/2009/05/11/django-foreign-key-default-value-example/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>GeoDjango: getting a random point within a multipolygon</title>
		<link>http://djangodays.com/2009/03/04/geodjango-getting-a-random-point-within-a-multipolygon/</link>
		<comments>http://djangodays.com/2009/03/04/geodjango-getting-a-random-point-within-a-multipolygon/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 11:05:22 +0000</pubDate>
		<dc:creator>Joost</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[GeoDjango]]></category>
		<category><![CDATA[Multipolygon]]></category>

		<guid isPermaLink="false">http://djangodays.com/?p=90</guid>
		<description><![CDATA[While fooling around with the awesome GeoDjango framework, I was looking for a way to generate a random point within a multipolygon.
Justin Bronn (djangopeople.net/jbronn/), the lead developer of GeoDjango was kind enough to point me in the right direction. I thought I share the concept here as it might be helpful to someone:
Define the function:

def [...]]]></description>
			<content:encoded><![CDATA[<p>While fooling around with the awesome <a href="http://geodjango.org/">GeoDjango</a> framework, I was looking for a way to generate a random point within a multipolygon.</p>
<p>Justin Bronn (<a href="http://djangopeople.net/jbronn/">djangopeople.net/jbronn/</a>), the lead developer of GeoDjango was kind enough to point me in the right direction. I thought I share the concept here as it might be helpful to someone:</p>
<p>Define the function:<br />
<code><br />
def get_random_point(extent):<br />
&nbsp;&nbsp;&nbsp;xrange = extent[2] - extent[0]<br />
&nbsp;&nbsp;&nbsp;yrange = extent[3] - extent[1]<br />
&nbsp;&nbsp;&nbsp;randx = xrange * random.random() + extent[0]<br />
&nbsp;&nbsp;&nbsp;randy = yrange * random.random() + extent[1]<br />
&nbsp;&nbsp;&nbsp;return Point(randx, randy)<br />
</code><br />
And then:<br />
<code><br />
extent = mpoly.extent<br />
pnt = get_random_point(extent)<br />
while not mpoly.contains(pnt):<br />
&nbsp;&nbsp;&nbsp;pnt = get_randomPoint(extent)<br />
</code><br />
Let me know what you think or if you&#8217;ve got any improvements!</p>
]]></content:encoded>
			<wfw:commentRss>http://djangodays.com/2009/03/04/geodjango-getting-a-random-point-within-a-multipolygon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More on debugging Django</title>
		<link>http://djangodays.com/2008/10/08/more-on-debugging-django/</link>
		<comments>http://djangodays.com/2008/10/08/more-on-debugging-django/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 13:59:21 +0000</pubDate>
		<dc:creator>Joost</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[debugging]]></category>

		<guid isPermaLink="false">http://djangodays.com/?p=46</guid>
		<description><![CDATA[The other day, I read about another interesting way of debugging Django Apps:
If you use the following statement in you code:
import pdb; pdb.set_trace()
You can debug you app by running the server with the python command
manage.py runserver -p 8888
Then, after you visit the page where the set_trace() function is called, the server will break the code [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, I read about another interesting way of debugging Django Apps:</p>
<p>If you use the following statement in you code:<br />
<code>import pdb; pdb.set_trace()</code></p>
<p>You can debug you app by running the server with the python command<br />
<code>manage.py runserver -p 8888</code></p>
<p>Then, after you visit the page where the set_trace() function is called, the server will break the code execution. If you then go to your terminal window, it will show you a prompt, at which you can go throught your code and variables.</p>
<p>Pretty good stuff!!</p>
]]></content:encoded>
			<wfw:commentRss>http://djangodays.com/2008/10/08/more-on-debugging-django/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>restrict access to Django site from all IP&#8217;s on Webfaction</title>
		<link>http://djangodays.com/2008/10/07/restrict-access-to-django-site-from-all-ips-on-webfaction/</link>
		<comments>http://djangodays.com/2008/10/07/restrict-access-to-django-site-from-all-ips-on-webfaction/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 13:28:36 +0000</pubDate>
		<dc:creator>Joost</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Django hosting]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Django tip]]></category>
		<category><![CDATA[ip filter]]></category>

		<guid isPermaLink="false">http://djangodays.com/?p=48</guid>
		<description><![CDATA[For this one project I wanted to deny all access to the site except for a certain IP address. I knew it could be done by using the mod_authz_host Apache Module (more info here), but I couldn&#8217;t get it to work on a Webfaction shared hosting account.
After exchanging some mails with the Webfaction support team [...]]]></description>
			<content:encoded><![CDATA[<p>For this one project I wanted to deny all access to the site except for a certain IP address. I knew it could be done by using the mod_authz_host Apache Module (more info <a href="http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html">here</a>), but I couldn&#8217;t get it to work on a <a href="http://www.webfaction.com/?affiliate=solidflux">Webfaction</a> shared hosting account.</p>
<p>After exchanging some mails with the Webfaction support team (which is absolutely awesome by the way: very helpfull and best response time i&#8217;ve seen!) I got it working! Thought I&#8217;d share the problem and the solution and might help save someone some frustration.</p>
<h3>The problem:</h3>
<p>I could not access the site when I tried the following in my httpd.conf:<br />
(xxx.xxx.xxx.xxx being the IP I wanted to grant access to)</p>
<p><code>&hellip;<br />
&lt;Location "/"&gt;<br />
    Order Deny,Allow<br />
    Deny from all<br />
    Allow from xxx.xxx.xxx.xxx<br />
&hellip;</code></p>
<p>I found the following line in my error_log:<br />
<code>[Fri Oct 03 06:10:47 2008] [error] [client 127.0.0.1] client denied by server configuration<br />
</code></p>
<p>This made something clear to me: Webfaction uses the apache2 webserver on a custom port, and the main webserver forwards the request through to the Django site. This works great but the problem here is that all the requests appear to be from 127.0.0.1 so I can&#8217;t exclude any ip&#8217;s in the httpd.conf file.</p>
<h3>The solution</h3>
<p>The solution is to use the Apache setenvif_module module to check for which ip the request was forwarded. Here&#8217;s part of an example httpd.conf file:<br />
<code>. . .<br />
LoadModule authz_host_module modules/mod_authz_host.so<br />
LoadModule setenvif_module modules/mod_setenvif.so<br />
&hellip;<br />
&lt;Location "/"&gt;</p>
<p>    # add a line like the following for each IP that you want to allow<br />
    SetEnvIf X-Forwarded-For "^xxx\.xxx\.xxx\.xxx$" allowed_ip</p>
<p>    Order Deny,Allow<br />
    Deny from all<br />
    Allow from env=allowed_ip<br />
&hellip;</code></p>
<p>If you got any questions about this, please use the comments below. If you&#8217;re looking for a good Django host for a reasonable price check out <a href="http://www.webfaction.com/?affiliate=solidflux">Webfaction </a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://djangodays.com/2008/10/07/restrict-access-to-django-site-from-all-ips-on-webfaction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django 1.0 mail notification of new comments</title>
		<link>http://djangodays.com/2008/10/02/django-10-mail-notification-of-new-comments/</link>
		<comments>http://djangodays.com/2008/10/02/django-10-mail-notification-of-new-comments/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 05:49:29 +0000</pubDate>
		<dc:creator>Joost</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[sending mail]]></category>
		<category><![CDATA[signals]]></category>

		<guid isPermaLink="false">http://djangodays.com/?p=35</guid>
		<description><![CDATA[There are some old samples available online for doing this, but the 1.0 version of Django is not compatible with those. So I thought I&#8217;d share my solution for sending notification mails whenever there&#8217;s been posted a new comment on my Django site using Django signals.
The old way of connecting to a signal was:
dispatcher.connect(myFunction, signal=models.signals.post_save, [...]]]></description>
			<content:encoded><![CDATA[<p>There are some old samples available online for doing this, but the 1.0 version of Django is not compatible with those. So I thought I&#8217;d share my solution for sending notification mails whenever there&#8217;s been posted a new comment on my Django site using Django signals.</p>
<p>The old way of connecting to a signal was:<br />
<code>dispatcher.connect(myFunction, signal=models.signals.post_save, sender=myModel)</code></p>
<p>The new way is:<br />
<code>models.signals.pre_save.connect(myFunction, sender=myModel)</code></p>
<p>So when you want to send an email whenever there&#8217;s a new comment posted by someone, without changing existing code you will have to do something like this:</p>
<p><code>from django.contrib.comments.models import Comment<br />
from django.core.mail import send_mail<br />
from django.db.models import signals</code></p>
<p><code>def mail_comment(instance, **kwargs):<br />
subject = 'subject of the mail'<br />
msg = 'Comment text:\n\n%s' % instance.comment<br />
send_mail(subject, msg, 'noreply@djangodays', ['email@djangodays.com'])</code></p>
<p><code>signals.post_save.connect(mail_comment, sender=Comment)</code></p>
<p>If you put this code in your __init__.py file it should work fine. Putting this in there is probably not the Django way of doing things, but I&#8217;m not sure where to put it instead&#8230; I anyone found a better way of doing this, please share it in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://djangodays.com/2008/10/02/django-10-mail-notification-of-new-comments/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Awesome Django Cheat sheet</title>
		<link>http://djangodays.com/2008/10/01/awesome-django-cheat-sheet/</link>
		<comments>http://djangodays.com/2008/10/01/awesome-django-cheat-sheet/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 06:34:34 +0000</pubDate>
		<dc:creator>Joost</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Cheat sheet]]></category>

		<guid isPermaLink="false">http://djangodays.com/?p=33</guid>
		<description><![CDATA[The guys from Mercurytide released an updated version of their superhandy Django Cheat Sheet. Especially useful when you&#8217;re just starting with Django.
http://www.mercurytide.co.uk/whitepapers/django-cheat-sheet/
]]></description>
			<content:encoded><![CDATA[<p>The guys from Mercurytide released an updated version of their superhandy Django Cheat Sheet. Especially useful when you&#8217;re just starting with Django.</p>
<p><a title="Django Cheat Sheet" href="http://www.mercurytide.co.uk/whitepapers/django-cheat-sheet/">http://www.mercurytide.co.uk/whitepapers/django-cheat-sheet/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://djangodays.com/2008/10/01/awesome-django-cheat-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error using New Comments in Django 1.0</title>
		<link>http://djangodays.com/2008/09/07/error-using-new-comments-in-django-10/</link>
		<comments>http://djangodays.com/2008/09/07/error-using-new-comments-in-django-10/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 10:21:26 +0000</pubDate>
		<dc:creator>Joost</dc:creator>
				<category><![CDATA[Errors]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Django 1.0]]></category>

		<guid isPermaLink="false">http://djangodays.com/?p=21</guid>
		<description><![CDATA[After upgrading to Django 1.0 I got the following error when using the new comment framework in one of my templates:
Caught an exception while rendering: Reverse for '' not found. 
After some searching I read somewhere I had to delete the old .pyc files (from before the Django upgrade). After doing that, everything worked as [...]]]></description>
			<content:encoded><![CDATA[<p>After upgrading to Django 1.0 I got the following error when using the new comment framework in one of my templates:</p>
<p><code>Caught an exception while rendering: Reverse for '' not found. </code></p>
<p>After some searching I read somewhere I had to delete the old .pyc files (from before the Django upgrade). After doing that, everything worked as it should!</p>
<p>Also, make sure you have the right path in your urls.py:<br />
<code>(r'^comments/', include('django.contrib.comments.urls')),</code></p>
<p>Hope this is usefull to anyone!</p>
]]></content:encoded>
			<wfw:commentRss>http://djangodays.com/2008/09/07/error-using-new-comments-in-django-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tip: Create models.py from existing database</title>
		<link>http://djangodays.com/2008/07/07/tip-create-modelspy-from-existing-database/</link>
		<comments>http://djangodays.com/2008/07/07/tip-create-modelspy-from-existing-database/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 01:03:45 +0000</pubDate>
		<dc:creator>Joost</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Django tip]]></category>
		<category><![CDATA[Snippet]]></category>

		<guid isPermaLink="false">http://djangodays.com/?p=4</guid>
		<description><![CDATA[Ever wanted to use an old, existing, legacy database with a Django Project? That&#8217;s totally possible!
Django allows you to create a models.py file based on an existing database. To do this, you first have to make sure your database settings are properly specified in the settings.py file. Here&#8217;s an example of what the database settings [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to use an old, existing, legacy database with a Django Project? That&#8217;s totally possible!</p>
<p>Django allows you to create a <em>models.py</em> file based on an existing database. To do this, you first have to make sure your database settings are properly specified in the <em>settings.py</em> file. Here&#8217;s an example of what the database settings in your <em>settings.py</em> file should look like:<br />
<code>DATABASE_ENGINE = ‘mysql’ # ‘postgresql_psycopg2′, ‘postgresql’, ‘mysql’, ’sqlite3′ or ‘oracle’.<br />
DATABASE_NAME = ‘YourDataBaseName’ # Or path to database file if using sqlite3.<br />
DATABASE_USER = ‘YourDataBaseUser’ # Not used with sqlite3.<br />
DATABASE_PASSWORD = ’YourVerySecretPassword’ # Not used with sqlite3.<br />
DATABASE_HOST = ” # Set to empty string for localhost. Not used with sqlite3.<br />
DATABASE_PORT = ” # Set to empty string for default. Not used with sqlite3.</code></p>
<p>Then, from the command line, type:</p>
<p><code>python mysite/manage.py inspectdb &gt; mysite/myapp/models.py</code></p>
<p>That should be all! Django created a <em>models.py </em>for you, based on the contents of the existing database.</p>
]]></content:encoded>
			<wfw:commentRss>http://djangodays.com/2008/07/07/tip-create-modelspy-from-existing-database/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
