<?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>finally{} &#187; django</title>
	<atom:link href="http://www.jjude.com/tag/django/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jjude.com</link>
	<description>all will be well finally</description>
	<lastBuildDate>Wed, 28 Dec 2011 18:00:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>S-I-P goes online</title>
		<link>http://www.jjude.com/2008/08/s-i-p-goes-online/</link>
		<comments>http://www.jjude.com/2008/08/s-i-p-goes-online/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 17:43:40 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/133</guid>
		<description><![CDATA[<p>Got my first Django application hosted. It wasn't that easy to get it hosting though.</p><p><a href="http://www.jjude.com/2008/08/s-i-p-goes-online/">S-I-P goes online</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>In an earlier <a href="http://jjude.com/2008/07/understanding-django-template-tags/" target="_blank">post</a>, I mentioned about developing a photo-blog in Django. I&#8217;m happy to announce that over the last week, I hosted in <a href="http://www.webfaction.com/" target="_blank">WebFaction</a> and it is online now.</p>
<p>I realized that hosting Django applications are not that easy &#8211; WordPress installation is easy &#8211; transfer files; setup some parameters and in about 5 minutes you are up and ready to go. That is the case even for a newbie. However it took me about a week to get this first installation up and running. I was even close to giving up out of frustration.</p>
<p>Good news is that I didn&#8217;t give up.</p>
<p>Surely <a href="http://www.webfaction.com/" target="_blank">WebFaction</a>, has made Django hosting easier. They have a single-click install of Django &#8211; be it with mod_python or with mod_wsgi. You can even choose the trunk version or the official release. Without these it would&#8217;ve been a nightmare for newbie like me to host Django applications.</p>
<p>My learning on Django hosting will be another post. This one is about the photo-blog.</p>
<p>As the images are hosted in Flickr, first step is to add <a href="http://www.flickr.com/services/api/misc.api_keys.html" target="_blank">Flickr API Key</a>.</p>
<p><a href="http://www.jjude.com/wp-content/uploads/image17.png"><img style="margin: 10px; border-width: 0px;" src="http://www.jjude.com/wp-content/uploads/image-thumb15.png" border="0" alt="image" width="260" height="64" /></a></p>
<p>Then you start to add photos by providing the Flickr Photo id:</p>
<p><a href="http://www.jjude.com/wp-content/uploads/image18.png"><img style="margin: 10px; border-width: 0px;" src="http://www.jjude.com/wp-content/uploads/image-thumb16.png" border="0" alt="image" width="260" height="49" /></a></p>
<p>I&#8217;m using <a href=" http://flickrapi.sourceforge.net/" target="_blank">Beej&#8217;s Flickr Python API</a> to connect to Flickr and get information. With the photo id, it will get the EXIF information, photo title, description and tags and store it locally. Once the information is obtained, if needed, it can be changed as well. If the information has to be obtained from Flickr again, just delete the title and it will fire the query again.</p>
<p>That&#8217;s all to be done to add a photo!</p>
<p>Coming to the homepage, I&#8217;ve designed a very simple homepage. (It shows up messed up in IE; it is ok in Firefox). Most of the part works &#8211; browse via tags, comments, about page etc. In the days to come, I want to incorporate the below features:</p>
<ul>
<li>Tags as a drop down in browse page</li>
<li>Email notification of comments</li>
<li>Comments moderation</li>
<li>Caching</li>
<li>Contact form</li>
</ul>
<p>At this moment, I&#8217;m not interested in voting or favorites. But might consider these as add-on features at a later time.</p>
<p>As always the code is hosted in <a href="http://code.google.com/p/s-i-p/" target="_blank">Google hosting</a>. Feel free to browse, comment, code review.</p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/07/understanding-django-template-tags/" title="Understanding Django Template Tags">Understanding Django Template Tags</a></li><li><a href="http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/" title="Say In Pixels &#8211; a photoblog in Django">Say In Pixels &#8211; a photoblog in Django</a></li><li><a href="http://www.jjude.com/2008/06/a-free-but-superb-django-hosting/" title="A free (but superb) Django hosting">A free (but superb) Django hosting</a></li></ul><p><a href="http://www.jjude.com/2008/08/s-i-p-goes-online/">S-I-P goes online</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/08/s-i-p-goes-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding Django Template Tags</title>
		<link>http://www.jjude.com/2008/07/understanding-django-template-tags/</link>
		<comments>http://www.jjude.com/2008/07/understanding-django-template-tags/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 15:23:10 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/93</guid>
		<description><![CDATA[<p>Is there a need for template tags? If there is no need, these guys wouldn't have put in so much effort into it. So how do I go about using it?</p><p><a href="http://www.jjude.com/2008/07/understanding-django-template-tags/">Understanding Django Template Tags</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>A photoblog is incomplete if there is no provision to display information, like EXIF, about the photo. For <a href="http://code.google.com/p/s-i-p/" target="_blank">S-I-P</a>, I need to pass these information to the templates. But what is a better way to do it? Variables can be passed via view functions and I&#8217;ve already done that. Per <a href="http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-tags" target="_blank">Django documentation</a>, something similar can be achieved via Template Tags too.</p>
<p>Okay now I&#8217;m confused. Should I use view function or template tags? If I could use view function to achieve the same, what is the need for template tags. I read and re-read, the otherwise excellent, Django documentation and Django Book. I couldn&#8217;t get a clarification.</p>
<p>Then I stumbled on <a href="http://www.b-list.org/weblog/" target="_blank">James Bennet</a>&#8216;s <a href="http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/" target="_blank">article</a> on Template tags. He makes it clear:</p>
<blockquote><p>If you want to have, say, a list of recently-added content which appears in a sidebar or footer on every page of a site, it&#8217;d be crazy to manually change every view to fetch that content and add it to the template context; a template tag is definitely the way to go.</p>
</blockquote>
<p>Let me re-word it: Let us say you want to display site name in all pages. Depending on the urls, you may have more than one view function. If so, then site name has to be included in all the context variable of each view function. Template Tags come to the rescue here. You can define a template tag and then it can be invoked from all the templates.</p>
<p>So here is how I implemented displaying site name in all templates.</p>
<p>First define the site name in settings.py; well ideally it should be defined in a db table. But I just starting with S-I-P. As I go along, I will change that.</p>
<pre>SITE_NAME = 'Say In Pixels'</pre>
<p>As per the above documentation that I referred, the templatetags should reside within the application (on the same level as models.py). So create a directory called templatetags and create a __init.py__ and another file which will contain the tags. The name of the file is important as it will invoked from templates. In my case I named it as sip_tags.py. Here is my directory structure.</p>
<pre>sip/
    models.py
    views.py
    templatetags/
    		__init.py__
	    	sip_tags.py</pre>
<p>As of now, sip_tags.py contains just one tag &#8211; one to return the site name that was defined in settings.py.</p>
<pre>from django import template
from django.conf import settings

register = template.Library()

@register.simple_tag
def site_name():
    return settings.SITE_NAME</pre>
<p>Now this has to be invoked from the templates. Here is how the html template looks like:</p>
<pre>{% load sip_tags %}{% block site_info %}&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;h1&gt;&lt;a href=&quot;/&quot;&gt;{% site_name %}&lt;/a&gt;&lt;/h1&gt;{% endblock site_info %}</pre>
<p>Note that sip_tags were loaded at the beginning of the template. site_name is available for all the templates and view functions can just handle the business logic.</p>
<p>(Thanks to the soul who is known as mkes in the <a href="irc://irc.freenode.net/django">#django IRC channel</a>. I was using {{ site_name }} and wondering why the hell it wasn&#8217;t appearing the output. He clarified it. That is the power of Django Community! One another reason why I like to program in Django)</p>
<p>References:<br />
  <br /><a href="http://www.djangoproject.com/documentation/templates_python/" target="_blank">The Django template language: For Python programmers</a></p>
<p><a href="http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/" target="_blank">Django tips: Write better template tags</a></p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/08/s-i-p-goes-online/" title="S-I-P goes online">S-I-P goes online</a></li><li><a href="http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/" title="Say In Pixels &#8211; a photoblog in Django">Say In Pixels &#8211; a photoblog in Django</a></li><li><a href="http://www.jjude.com/2008/06/a-free-but-superb-django-hosting/" title="A free (but superb) Django hosting">A free (but superb) Django hosting</a></li></ul><p><a href="http://www.jjude.com/2008/07/understanding-django-template-tags/">Understanding Django Template Tags</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/07/understanding-django-template-tags/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Say In Pixels &#8211; a photoblog in Django</title>
		<link>http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/</link>
		<comments>http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 02:11:12 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/90</guid>
		<description><![CDATA[<p>As a support tool to learn Photography, I am planning to create a Photoblog. I am sure it is gonna be fun doing it.</p><p><a href="http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/">Say In Pixels &#8211; a photoblog in Django</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>I love to take photos. And show off!</p>
<p>The problem is I don&#8217;t take good photos. To take good photos, I need to take lots of photos. I will take lots of photos, if I can show off. To show off, I need an easy to use application which fits my bill. See my problem?</p>
<p>To host a photoblog, one needs enormous disk space which demands enormous money. <img src='http://www.jjude.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  Okay there is <a href="http://flickr.com/photos/jjude/" target="_blank">Flickr</a> (leaving aside Microsoft&#8217;s attempt to mess it up). But Flickr allows only members to comment. And it is not well suited as a photoblog.</p>
<p>So I decided to write a photoblog on my own. It is easier to code it on my own rather than complaining about all the existing ones. (May be someone else will complain about mine. But then, that would indicate that mine became popular!)</p>
<p>So here are the feature list that my photoblog will have:</p>
<ol>
<li><strong>Will be Django based</strong> &#8211; Cool way to learn Django. If I can&#8217;t use technology to solve my problem, how can I use it to solve other&#8217;s problems. </li>
<li><strong>Flickr Integration</strong> &#8211; I&#8217;ll keep Flickr as primary storage.</li>
<li><strong>Tagging</strong> &#8211; Categories are one dimensional. Lets get away from it. Read more at <a href="http://www.organizepictures.com/" target="_blank">Organize Pictures</a>. How cool it would be if <a href="http://en.wikipedia.org/wiki/Exif" target="_blank">EXIF</a> data also is used as tags?</li>
<li><strong>All other generic blog features</strong> &#8211; like comments, archives and the rest.</li>
<li><a href="http://www.pixelpost.org/" target="_blank"><strong>PixelPost</strong></a><strong> in Django?</strong> &#8211; # 1 photoblog application. But that is in PHP. Can I match it in features &#8211; especially easy to install? &#8211; and in popularity?</li>
<li><a href="http://code.google.com/p/s-i-p/" target="_blank"><strong>Hosted in Google</strong></a> &#8211; Where else?</li>
</ol>
<p>Am sure to pull through <a href="http://code.google.com/p/s-i-p/" target="_blank">s-i-p</a>. Only time will tell if I become a better photographer.</p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/08/s-i-p-goes-online/" title="S-I-P goes online">S-I-P goes online</a></li><li><a href="http://www.jjude.com/2008/07/understanding-django-template-tags/" title="Understanding Django Template Tags">Understanding Django Template Tags</a></li><li><a href="http://www.jjude.com/2008/06/a-free-but-superb-django-hosting/" title="A free (but superb) Django hosting">A free (but superb) Django hosting</a></li></ul><p><a href="http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/">Say In Pixels &#8211; a photoblog in Django</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>A free (but superb) Django hosting</title>
		<link>http://www.jjude.com/2008/06/a-free-but-superb-django-hosting/</link>
		<comments>http://www.jjude.com/2008/06/a-free-but-superb-django-hosting/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 18:07:27 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/88</guid>
		<description><![CDATA[<p>Are you looking for a web-host for your Django projects? You can't beat bells-n-whistles.</p><p><a href="http://www.jjude.com/2008/06/a-free-but-superb-django-hosting/">A free (but superb) Django hosting</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>Ever since I stared to learn Django, I&#8217;ve looking for a web-host to host the apps that I develop &#8211; so that I can learn the every bit of the learning chain: from design until hosting. As it was for learning purpose, I didn&#8217;t want to pay heavily for it. So primarily I was looking for some free hosting service.</p>
<p>I came to know via <a href="http://groups.google.com/group/django-users/" target="_blank">Django Google Groups</a> that <a title="http://bells-n-whistles.net/" href="http://bells-n-whistles.net/">bells-n-whistles</a> provide a fee hosting service. I sent them a mail via their contact form. They setup the free domain and sent me a mail regarding the details. Their free hosting access is only via FTP.</p>
<p>I had starting glitches with the hosting. Every time I sent them a mail, they were very prompt in answering back. Being a newbie into Django (especially its hosting), I probably asked silly and annoying questions. Not minding, they replied back with answers &#8211; simple yet to the point.</p>
<p>There is no detailed documentation on their site. So here is what worked for me.</p>
<p>Here is the snippet of settings.py</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PROJECT_DIR <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">dirname</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">abspath</span><span style="color: black;">&#40;</span>__file__<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
DATABASE_ENGINE <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'sqlite3'</span><br />
DATABASE_NAME <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>PROJECT_DIR<span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'sol.db'</span><span style="color: black;">&#41;</span><br />
MEDIA_ROOT <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'%s'</span> % PROJECT_DIR<br />
MEDIA_URL <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'media/'</span><br />
ADMIN_MEDIA_PREFIX <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'/media/'</span><br />
TEMPLATE_DIRS <span style="color: #66cc66;">=</span> <span style="color: black;">&#40;</span><br />
&nbsp; &nbsp; r<span style="color: #483d8b;">'%s/templates/sol'</span> % PROJECT_DIR<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; r<span style="color: #483d8b;">'%s/templates'</span> % PROJECT_DIR<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; r<span style="color: #483d8b;">'%s/templates/admin'</span> % PROJECT_DIR<span style="color: #66cc66;">,</span><br />
<span style="color: black;">&#41;</span><br />
<br />
INSTALLED_APPS <span style="color: #66cc66;">=</span> <span style="color: black;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'django.contrib.auth'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'django.contrib.contenttypes'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'django.contrib.sessions'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'django.contrib.admin'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: #483d8b;">'sol'</span><span style="color: #66cc66;">,</span><br />
<span style="color: black;">&#41;</span></div></div>
<p>As you can see, I am using sqlite instead of their default db PostgreSQL. As it is a demo db, it works okay for me.</p>
<p>Then transfer both application templates and admin templates to templates directory. Transfer css files to media directory. If you have file uploads (like images or avatars), they should be within media directory as well.</p>
<p>Of course since it is a free hosting, you need to add a link to their site. For the free service that they provide, it is expected. If I continue to learn Django (I&#8217;ll be), then I will most probably, go with them for hosting.</p>
<p>You can visit their site at: <a href="http://bells-n-whistles.net/">bells-n-whistles</a>. The one that I&#8217;m hosting is at: <a title="http://cephire.bells-n-whistles.net" href="http://cephire.bells-n-whistles.net">http://cephire.bells-n-whistles.net</a>. (Since it is a demo and just setup, there is not much there. Hope to add over the time. It is a Twitter clone. If you want to try it out, use jjude/jjude for user id/password).</p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/08/s-i-p-goes-online/" title="S-I-P goes online">S-I-P goes online</a></li><li><a href="http://www.jjude.com/2008/07/understanding-django-template-tags/" title="Understanding Django Template Tags">Understanding Django Template Tags</a></li><li><a href="http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/" title="Say In Pixels &#8211; a photoblog in Django">Say In Pixels &#8211; a photoblog in Django</a></li></ul><p><a href="http://www.jjude.com/2008/06/a-free-but-superb-django-hosting/">A free (but superb) Django hosting</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/06/a-free-but-superb-django-hosting/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Adding RSS feeds to Django Applications</title>
		<link>http://www.jjude.com/2008/06/adding-rss-feeds-to-django-applications/</link>
		<comments>http://www.jjude.com/2008/06/adding-rss-feeds-to-django-applications/#comments</comments>
		<pubDate>Sat, 07 Jun 2008 15:12:23 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/85</guid>
		<description><![CDATA[<p>Django supports 'feeds' out-of-the-box. All it takes is, couple of minutes of thought (to frame feed structure) and probably an hour to roll it out.</p><p><a href="http://www.jjude.com/2008/06/adding-rss-feeds-to-django-applications/">Adding RSS feeds to Django Applications</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>Being a relatively &#8216;young&#8217; framework, most of the requirements for building social applications works right out-of-the-box from Django. One such feature is &#8216;feeds&#8217;. Here is how I built &#8216;feeds&#8217; for <a href="http://code.google.com/p/s-o-l/" target="_blank">SOL</a>.</p>
<h5>URLs</h5>
<p>I followed the convention and url for the feeds are in &#8216;/feeds/&#8217;. Make the below changes to urls.py.</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">urlpatterns +<span style="color: #66cc66;">=</span> patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">'django.contrib.syndication.views'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; <span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^feeds/(?P&lt;url&gt;.*)/$'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'feed'</span><span style="color: #66cc66;">,</span> <span style="color: black;">&#123;</span><span style="color: #483d8b;">'feed_dict'</span>: <span style="color: black;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'latest'</span>: LatestSOLs<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'user'</span>: UserSOLs<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'group'</span>: GroupSOLs<span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
<span style="color: black;">&#41;</span></div></div>
<p>What this means is that, there are three feeds available &#8211; one of the latest entries, one for the user entries and another for the group. The corresponding functions should be in feeds.py.</p>
<h5>Feeds</h5>
<p>The easiest one is to create feed for all the entries: just derive from Feed class; define title, link and description for the feed; return the entries. Django does the rest of the stuff.</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">class</span> LatestSOLs<span style="color: black;">&#40;</span>Feed<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; title <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'%s : Latest SOLs'</span> % settings.<span style="color: black;">SITE_NAME</span><br />
&nbsp; &nbsp; link <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'/'</span><br />
&nbsp; &nbsp; description <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'Latest entries to %s'</span> % settings.<span style="color: black;">SITE_NAME</span><br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> items<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> sol.<span style="color: black;">objects</span>.<span style="color: black;">order_by</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-date'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:settings.<span style="color: black;">FEED_SIZE</span><span style="color: black;">&#93;</span></div></div>
<p>It gets little complex when parameters are passed via URL, user id or group id, and feed should be built accordingly. You need to find the object (user or group) and filter accordingly.</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">class</span> UserSOLs<span style="color: black;">&#40;</span>Feed<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; title_template <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'feeds/title.html'</span><br />
&nbsp; &nbsp; description_template <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'feeds/description.html'</span><br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> get_object<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> bits<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>bits<span style="color: black;">&#41;</span> &amp;lt<span style="color: #66cc66;">;</span> <span style="color: #ff4500;">1</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">raise</span> ObjectDoesNotExist<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> userprofile.<span style="color: black;">objects</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span>user__username__exact<span style="color: #66cc66;">=</span>bits<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> title<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> obj<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;SOLs of '%s'&quot;</span> % obj.<span style="color: black;">nickname</span><br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> link<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> obj<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;/&quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> description<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> obj<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;SOLs recently posted by %s&quot;</span> % obj.<span style="color: black;">nickname</span><br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> items<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> obj<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> sol.<span style="color: black;">objects</span>.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>author__username<span style="color: #66cc66;">=</span>obj.<span style="color: #dc143c;">user</span>.<span style="color: black;">username</span><span style="color: black;">&#41;</span>.<span style="color: black;">order_by</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-date'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:settings.<span style="color: black;">FEED_SIZE</span><span style="color: black;">&#93;</span></div></div>
<h5>Templates</h5>
<p>You need to design a template for title and description of the feeds. They are pretty simple.</p>
<p>title.html</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: black;">&#123;</span><span style="color: black;">&#123;</span> obj.<span style="color: black;">get_author_nickname</span> <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span> - <span style="color: black;">&#123;</span><span style="color: black;">&#123;</span> obj.<span style="color: black;">date</span>|date:<span style="color: #483d8b;">&quot;M-d G:i&quot;</span> <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span></div></div>
<p>It can be as simple as {{ obj.title }}</p>
<p>description.html</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: black;">&#123;</span><span style="color: black;">&#123;</span> obj.<span style="color: black;">body</span> <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span></div></div>
<p>Feeds are ready. They need to be included in the home page templates so that browsers can identify them.</p>
<p>For all entries:</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: black;">&#123;</span>% block feeds %<span style="color: black;">&#125;</span><br />
<span style="color: #66cc66;">&lt;</span>link rel<span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;alternate&quot;</span> <span style="color: #008000;">type</span><span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;application/rss+xml&quot;</span> title<span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;Public Feeds&quot;</span> href<span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;/feeds/latest/&quot;</span><span style="color: #66cc66;">&gt;</span><br />
<span style="color: black;">&#123;</span>%endblock feeds%<span style="color: black;">&#125;</span></div></div>
<p>For feeds specific to a user:</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: black;">&#123;</span>% block feeds %<span style="color: black;">&#125;</span><br />
<span style="color: #66cc66;">&lt;</span>link rel<span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;alternate&quot;</span> <span style="color: #008000;">type</span><span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;application/rss+xml&quot;</span> title<span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;User Feeds&quot;</span> href<span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;/feeds/user/{{u_id}}&quot;</span> /<span style="color: #66cc66;">&gt;</span><br />
<span style="color: black;">&#123;</span>%endblock feeds%<span style="color: black;">&#125;</span></div></div>
<p>That&#8217;s all needed to enable feeds for your social application.</p>
<p>You can browse the code from <a href="http://code.google.com/p/s-o-l/source/browse" target="_blank">google hosting</a>.</p>
<h5>References</h5>
<p><a title="http://www.djangoproject.com/documentation/syndication_feeds/" href="http://www.djangoproject.com/documentation/syndication_feeds/" target="_blank">http://www.djangoproject.com/documentation/syndication_feeds/</a></p>
<p><a title="http://www.andrlik.org/blog/2007/aug/03/fun-with-django-feeds/" href="http://www.andrlik.org/blog/2007/aug/03/fun-with-django-feeds/" target="_blank">http://www.andrlik.org/blog/2007/aug/03/fun-with-django-feeds/</a></p>
<p id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:324df145-c70f-45f4-8d42-2157bda96d54" class="wlWriterSmartContent" style="margin: 0px; padding: 0px; display: inline;">del.icio.us Tags: <a rel="tag" href="http://del.icio.us/popular/django">django</a>,<a rel="tag" href="http://del.icio.us/popular/rss">rss</a>,<a rel="tag" href="http://del.icio.us/popular/syndication">syndication</a></p>
<p id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:270f77ab-b016-4121-baaf-1cfaff74f9a9" class="wlWriterSmartContent" style="margin: 0px; padding: 0px; display: inline;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/django">django</a>,<a rel="tag" href="http://technorati.com/tags/rss">rss</a>,<a rel="tag" href="http://technorati.com/tags/syndication">syndication</a></p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/08/s-i-p-goes-online/" title="S-I-P goes online">S-I-P goes online</a></li><li><a href="http://www.jjude.com/2008/07/understanding-django-template-tags/" title="Understanding Django Template Tags">Understanding Django Template Tags</a></li><li><a href="http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/" title="Say In Pixels &#8211; a photoblog in Django">Say In Pixels &#8211; a photoblog in Django</a></li></ul><p><a href="http://www.jjude.com/2008/06/adding-rss-feeds-to-django-applications/">Adding RSS feeds to Django Applications</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/06/adding-rss-feeds-to-django-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling ManyToMany field in Django</title>
		<link>http://www.jjude.com/2008/05/handling-manytomany-field-in-django/</link>
		<comments>http://www.jjude.com/2008/05/handling-manytomany-field-in-django/#comments</comments>
		<pubDate>Sat, 24 May 2008 18:10:42 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/83</guid>
		<description><![CDATA[<p>How to handle M2M in Models and Templates.</p><p><a href="http://www.jjude.com/2008/05/handling-manytomany-field-in-django/">Handling ManyToMany field in Django</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m still learning Django; but as I learn more and more I admire the thoughtfulness of those who designed the framework. They&#8217;ve surely made complex things easy and simple things easier.</p>
<p>I continue to learn Django by creating applications that I will use &#8211; either at office or at home. First I created <a href="http://code.google.com/p/s-o-l/" target="_blank">SOL</a> (a microblog) to be used at office; Now I&#8217;m developing a book inventory application for my own use.</p>
<p>In this application, I have a M2M model &#8211; book and authors.</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">class</span> Author<span style="color: black;">&#40;</span>models.<span style="color: black;">Model</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; name <span style="color: #66cc66;">=</span> models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length<span style="color: #66cc66;">=</span><span style="color: #ff4500;">45</span><span style="color: black;">&#41;</span><br />
<br />
<br />
<span style="color: #ff7700;font-weight:bold;">class</span> Book<span style="color: black;">&#40;</span>models.<span style="color: black;">Model</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span style="color: black;">authors</span> <span style="color: #66cc66;">=</span> models.<span style="color: black;">ManyToManyField</span><span style="color: black;">&#40;</span>Author<span style="color: #66cc66;">,</span> verbose_name<span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;Authors&quot;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; ...</div></div>
<p>Django&#8217;s Many-to-Many relation documentation is pretty detailed. I couldn&#8217;t find much details on using M2M in a template. However, it was explained in <a href="http://groups.google.com/group/django-users/browse_thread/thread/3900aca4d5549f4/d3cbc7fe76c84db1?lnk=gst&amp;q=many+to+many+template#d3cbc7fe76c84db1" target="_blank">Google Group</a>.</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>p<span style="color: #66cc66;">&gt;</span><span style="color: black;">&#123;</span>% <span style="color: #ff7700;font-weight:bold;">for</span> item <span style="color: #ff7700;font-weight:bold;">in</span> query_list %<span style="color: black;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&lt;</span>tr <span style="color: #ff7700;font-weight:bold;">class</span><span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;itemrow&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>td <span style="color: #ff7700;font-weight:bold;">class</span><span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;itemcol&quot;</span><span style="color: #66cc66;">&gt;</span> <span style="color: black;">&#123;</span><span style="color: black;">&#123;</span>item.<span style="color: black;">title</span><span style="color: black;">&#125;</span><span style="color: black;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; <span style="color: #66cc66;">&lt;</span>/td<span style="color: #66cc66;">&gt;&lt;</span>td <span style="color: #ff7700;font-weight:bold;">class</span><span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;itemcol&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span>% <span style="color: #ff7700;font-weight:bold;">for</span> author <span style="color: #ff7700;font-weight:bold;">in</span> item.<span style="color: black;">authors</span>.<span style="color: #008000;">all</span> %<span style="color: black;">&#125;</span> <span style="color: #66cc66;">&lt;</span>br /<span style="color: #66cc66;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span><span style="color: black;">&#123;</span>author.<span style="color: black;">name</span><span style="color: black;">&#125;</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: black;">&#123;</span>%endfor %<span style="color: black;">&#125;</span><span style="color: #66cc66;">&lt;</span>/td<span style="color: #66cc66;">&gt;&lt;</span>/tr<span style="color: #66cc66;">&gt;</span><br />
<span style="color: black;">&#123;</span>% endfor %<span style="color: black;">&#125;</span><span style="color: #66cc66;">&lt;</span>/p<span style="color: #66cc66;">&gt;</span></div></div>
<p>If you are implementing AJAX, you may want to compile the rows into a list. That can be achieved by:</p>
<div class="codecolorer-container python blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rows <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'id'</span>: book.<span style="color: #008000;">id</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'cell'</span>: <span style="color: black;">&#91;</span>book.<span style="color: black;">title</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">' &amp;amp; '</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>auth.<span style="color: black;">name</span> <span style="color: #ff7700;font-weight:bold;">for</span> auth <span style="color: #ff7700;font-weight:bold;">in</span> book.<span style="color: black;">authors</span>.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> book.<span style="color: black;">publisher</span><span style="color: #66cc66;">,</span> book.<span style="color: black;">isbn</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span> <span style="color: #ff7700;font-weight:bold;">for</span> book <span style="color: #ff7700;font-weight:bold;">in</span> books<span style="color: black;">&#93;</span></div></div>
<p>Don&#8217;t know if that&#8217;s all to M2M. But this all I&#8217;ve learnt.</p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/08/s-i-p-goes-online/" title="S-I-P goes online">S-I-P goes online</a></li><li><a href="http://www.jjude.com/2008/07/understanding-django-template-tags/" title="Understanding Django Template Tags">Understanding Django Template Tags</a></li><li><a href="http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/" title="Say In Pixels &#8211; a photoblog in Django">Say In Pixels &#8211; a photoblog in Django</a></li></ul><p><a href="http://www.jjude.com/2008/05/handling-manytomany-field-in-django/">Handling ManyToMany field in Django</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/05/handling-manytomany-field-in-django/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Building a Book Inventory in Django</title>
		<link>http://www.jjude.com/2008/05/building-a-book-inventory-in-django/</link>
		<comments>http://www.jjude.com/2008/05/building-a-book-inventory-in-django/#comments</comments>
		<pubDate>Sun, 18 May 2008 05:59:46 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/82</guid>
		<description><![CDATA[<p>Learning Django by building something useful to me (and probably for others too)</p><p><a href="http://www.jjude.com/2008/05/building-a-book-inventory-in-django/">Building a Book Inventory in Django</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a voracious reader. With such a hobby I&#8217;ve gotten loads of books. Many-a-times, I tried to take an inventory of the books but failed, primarily because of laziness. With the recent passion with Django, I thought why not build something that will help me learn Django as well as which will be useful to me. If it comes out well, it may be useful to others as well.</p>
<p>So far it has gone on well. I&#8217;ve learnt about the below aspects as I built iCat (I got to work around the name that I came up with, because there was already a project in Sourceforge with the name that I needed).</p>
<ul>
<li>Using Many-To-Many Field in Django </li>
<li>Building forms for models </li>
<li>Retrieving book details via Amazon REST </li>
</ul>
<p>That is the progress that I&#8217;ve made so far. I want the below features built so that it is useful.</p>
<ul>
<li>Ajax Integration </li>
<li>Barcode Integration </li>
</ul>
<p>I&#8217;m planning to use jQuery for Ajax. I still need to find an &#8216;open source&#8217; Barcode reader. I don&#8217;t want to buy a Barcode reader; I want to use the webcam or the camera attached with the mobile. If you&#8217;ve any suggestions, please let me know.</p>
<p>I&#8217;m sure if it all works out well, then I&#8217;ll build a book inventory easily and keep it updated too.</p>
<p>If you are interested, check out the code at <a href="http://code.google.com/p/i-cat/source/browse" target="_blank">Google Code</a>.</p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/08/s-i-p-goes-online/" title="S-I-P goes online">S-I-P goes online</a></li><li><a href="http://www.jjude.com/2008/07/understanding-django-template-tags/" title="Understanding Django Template Tags">Understanding Django Template Tags</a></li><li><a href="http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/" title="Say In Pixels &#8211; a photoblog in Django">Say In Pixels &#8211; a photoblog in Django</a></li></ul><p><a href="http://www.jjude.com/2008/05/building-a-book-inventory-in-django/">Building a Book Inventory in Django</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/05/building-a-book-inventory-in-django/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pagination in Django</title>
		<link>http://www.jjude.com/2008/05/pagination-in-django/</link>
		<comments>http://www.jjude.com/2008/05/pagination-in-django/#comments</comments>
		<pubDate>Mon, 12 May 2008 16:32:08 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/81</guid>
		<description><![CDATA[<p>Django offers a simple pagination as a out-of-the-box feature. Pretty cool one.</p><p><a href="http://www.jjude.com/2008/05/pagination-in-django/">Pagination in Django</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>Most often it is necessary to paginate the results. Django comes up with a simple but pretty neat pagination out-of-the-box. Paginating is easy and simple.</p>
<p>Import first:</p>
<pre>from django.core.paginator import Paginator, InvalidPage </pre>
<p>Get the results. I read somewhere that Django delays execution of queries until necessary. If so, then this will not impact any performance.</p>
<pre>info_list = Paginator(sol.objects.all(),paginate_by) </pre>
<p>Now build the dictionary values to be passed to the template.</p>
<pre>
try:
	page_info = info_list.page(page_num)
except InvalidPage:
	page_num = 1
	page_info = info_list.page(page_num)

has_previous = page_info.has_previous()
has_next = page_info.has_next()

info_dict = {
	'query_list' : page_info.object_list,
	'has_previous' : page_info.has_previous(),
	'previous_page' : page_info.previous_page_number(),
	'has_next' : page_info.has_next(),
	'next_page' : page_info.next_page_number(),
	'site_name' : 'sol',
	'user' : request.user,
}</pre>
<p>That is it. Now this can be called as:</p>
<pre>
{% for item in query_list %}
&lt;tr class=&quot;itemrow&quot;&gt;
&lt;td class=&quot;itemcol&quot;&gt;&lt;a href=&quot;{{ item.get_absolute_url }}&quot;&gt; {{item.title}}&lt;/a&gt;&lt;/td&gt;
&lt;td class=&quot;itemcol&quot;&gt;
&lt;ul&gt;
{% for author in item.authors.all %}
    &lt;li&gt; &lt;a href=&quot;{{author.get_absolute_url}}&quot; title=&quot;{{author.name}}&quot;&gt;{{author.name}}&lt;/a&gt; &lt;/li&gt;
{%endfor %}
&lt;/ul&gt;
&lt;/td&gt;
&lt;/tr&gt;
{% endfor %}</pre>
<p>This will enable pagination for the entries. Simple right?</p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/08/s-i-p-goes-online/" title="S-I-P goes online">S-I-P goes online</a></li><li><a href="http://www.jjude.com/2008/07/understanding-django-template-tags/" title="Understanding Django Template Tags">Understanding Django Template Tags</a></li><li><a href="http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/" title="Say In Pixels &#8211; a photoblog in Django">Say In Pixels &#8211; a photoblog in Django</a></li></ul><p><a href="http://www.jjude.com/2008/05/pagination-in-django/">Pagination in Django</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/05/pagination-in-django/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Learning to test</title>
		<link>http://www.jjude.com/2008/05/learning-to-test/</link>
		<comments>http://www.jjude.com/2008/05/learning-to-test/#comments</comments>
		<pubDate>Mon, 05 May 2008 16:53:57 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/75</guid>
		<description><![CDATA[<p>Along with learning Python, I am learning other components of web development - most importantly testing.</p><p><a href="http://www.jjude.com/2008/05/learning-to-test/">Learning to test</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>I started programming in C. Then moved to VB and VC++. Then I moved to packaged software solutions like Vantive and Peoplesoft. In all these days, I managed not to write automated test cases. It is not that I didn&#8217;t want to, but it wasn&#8217;t the practice. I spent most of my time, learning and programming tools, languages and other similar aspects but never concentrated on automated testing.</p>
<p>But when one starts to write an application on their own, their perspective differ. More so when it is an open source. Now I want to test my software enough to avoid embarrassment in the community. I don&#8217;t want to release a (open-source) software without testing. It is not that the application will not contain any bugs; but I&#8217;ve taken all the steps that I know to make the application bug-free.</p>
<p>When one treads on an unknown territory any kind of hand-holding is appreciated. With detailed documentation, Django makes it easier to get into testing territory. Because of the fear of unknown, I&#8217;ve been postponing writing test cases for days. Then one evening, I sat down, read through Django&#8217;s documentation on test cases, browsed few more sample test cases (that is the beauty of open source) and I started to write test cases. It wasn&#8217;t scared of writing test cases any more. It came in so easily!</p>
<p>Okay! I haven&#8217;t yet done the full test suite. I&#8217;ve understood and managed to write test cases to test the views alone (Django Test Client). I still need to write detailed unit test cases and in-browser testing.</p>
<p>But at least this is a good start.</p>
<p>P.S: You can browse the the tests as part of <a title="http://code.google.com/p/s-o-l/" href="http://code.google.com/p/s-o-l/">http://code.google.com/p/s-o-l/</a></p>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/08/s-i-p-goes-online/" title="S-I-P goes online">S-I-P goes online</a></li><li><a href="http://www.jjude.com/2008/07/understanding-django-template-tags/" title="Understanding Django Template Tags">Understanding Django Template Tags</a></li><li><a href="http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/" title="Say In Pixels &#8211; a photoblog in Django">Say In Pixels &#8211; a photoblog in Django</a></li></ul><p><a href="http://www.jjude.com/2008/05/learning-to-test/">Learning to test</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/05/learning-to-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django application as a stand-alone desktop application</title>
		<link>http://www.jjude.com/2008/04/make-your-django-application-as-a-stand-alone-desktop-application/</link>
		<comments>http://www.jjude.com/2008/04/make-your-django-application-as-a-stand-alone-desktop-application/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 15:38:29 +0000</pubDate>
		<dc:creator>Joseph Jude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.jjude.com/index.php/archives/70</guid>
		<description><![CDATA[<p>After frustration comes success. I made SOL (a Twitter clone) a stand-alone desktop application.</p><p><a href="http://www.jjude.com/2008/04/make-your-django-application-as-a-stand-alone-desktop-application/">Django application as a stand-alone desktop application</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></description>
			<content:encoded><![CDATA[<p>There are few options available to package Django as a stand-alone desktop apps. They are:</p>
<ul>
<li>cx_freeze</li>
<li>PyInstaller</li>
<li>Py2exe</li>
<li>dbuilder.py</li>
</ul>
<p><a href="http://www.silverstripesoftware.com/blog/archives/51" target="_blank">Siddharta</a> already packaged Django as a windows application using cx_freeze. I based my experiment on his entry. Though he has explained it pretty well, being a python/django newbie, I needed a lot more than what he explained in his article.</p>
<p>I read pages after pages and spent about a week in making a desktop app of SOL. I didn&#8217;t make much progress and was very frustrated. (I wrote about it <a href="http://jjude.com/2008/04/make-your-django-application-as-a-stand-alone-desktop-application/" target="_blank">here</a>). After a time, I switched to py2exe, as I was not able to locate much info about cx_freeze.</p>
<p>I used py2exe, sqlite and cherrypy for packaging as a desktop app. As it is only for demo purpose, I would&#8217;ve preferred to have the default development server itself. But I don&#8217;t know how to do it; and info about cherrypy was readily available.</p>
<p>Fundamentally, you need to import all of the required Django modules. That takes the most of the time. Whenever I got, &#8216;module&#8217; object has no attribute &#8216;xxxx&#8217;, I had to trace it to one of Django&#8217;s module and import it.</p>
<p>Once I got all of the modules, I had to integrate with CherryPy. It wasn&#8217;t difficult as info was already available. However, admin css were not delivered. I read through &#8216;AdminMediaHandler&#8217; code and understood that I had to pass an absolute path for admin media folder. That got me both local media and admin media done.</p>
<p>I had to make only one change to settings.py. I replaced</p>
<pre>os.path.dirname(os.path.abspath(__file__))</pre>
<p>with</p>
<pre>sys.argv[0]</pre>
<p>I was glad that I persevered to make this. Here I post the setup, imports and the build script with the hope that it might be useful for others.</p>
<p>This is the first file &#8211; sol.py</p>
<pre>#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os, sys

os.environ['DJANGO_SETTINGS_MODULE'] = "settings"
#these pertain to your application
import sol.models
import sol.views
import urls
import manage
import settings
#these are django imports
import django.template.loaders.filesystem
import django.template.loaders.app_directories
import django.middleware.common
import django.contrib.sessions.middleware
import django.contrib.auth.middleware
import django.middleware.doc
import django.contrib.auth
import django.contrib.contenttypes
import django.contrib.sessions
import django.contrib.sessions.backends.db
import django.contrib.sites
import django.contrib.admin
import django.core.cache.backends
import django.db.backends.sqlite3.base
import django.db.backends.sqlite3.introspection
import django.db.backends.sqlite3.creation
import django.db.backends.sqlite3.client
import django.template.defaulttags
import django.template.defaultfilters
import django.template.loader_tags

import django.contrib.admin.urls
from django.conf.urls.defaults import *
import django.contrib.admin.views.main
import django.core.context_processors
import django.contrib.auth.views
import django.contrib.auth.backends
import django.views.static
import django.contrib.admin.templatetags.adminmedia
import django.contrib.admin.templatetags.adminapplist
import django.contrib.admin.templatetags.admin_list
import django.contrib.admin.templatetags.admin_modify
import django.contrib.admin.templatetags.log
import django.contrib.admin.views.auth
import django.contrib.admin.views.doc
import django.contrib.admin.views.template
import django.conf.urls.shortcut
import django.views.defaults

#dont need to import these pkgs
#need to know how to exclude them
import email.mime.audio
import email.mime.base
import email.mime.image
import email.mime.message
import email.mime.multipart
import email.mime.nonmultipart
import email.mime.text
import email.charset
import email.encoders
import email.errors
import email.feedparser
import email.generator
import email.header
import email.iterators
import email.message
import email.parser
import email.utils
import email.base64mime
import email.quoprimime
import django.core.cache.backends.locmem
import django.templatetags.i18n
import django.views.i18n

#let us hook up cherrypy
#is it possible to hook up the dev server itself?
from cherrypy import wsgiserver
import cherrypy
from django.core.handlers.wsgi import WSGIHandler
from django.core.servers.basehttp import AdminMediaHandler

if __name__ == "__main__":
    print '*****************************************************'
    print 'Open your browser and point to http://localhost:8000'
    print 'To close, press ctrl-c'
    print ''
    print 'local user id is: jjude; password is also jjude'
    print 'admin user id is: admin; password is also admin'
    print '*****************************************************'
    os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
    # Set up site-wide config first so we get a log if errors occur.

    cherrypy.config.update({'environment': 'production',
                            'log.error_file': 'site.log',
                            'log.screen': False})

    try:
        sys.path.insert(0,"..")
        #2nd param to AdminMediaHandler should be absolute path to the admin media files
        cherrypy.tree.graft(AdminMediaHandler(WSGIHandler(),media_dir=os.path.dirname(os.path.abspath(sys.argv[0])) + settings.ADMIN_MEDIA_PREFIX), '/')
        cherrypy.server.socket_port = 8000
        cherrypy.server.quickstart()
        cherrypy.engine.start()

    except KeyboardInterrupt:
        cherrypy.server.stop()</pre>
<p>This is setup.py</p>
<pre>from distutils.core import setup
import py2exe
import glob

setup(
    options = {"py2exe": {"compressed": 1,
                          "optimize": 2,
                          "ascii": 1,
                          "bundle_files": 1,
                          "packages":["encodings"],
                           "excludes" : ["pywin", "pywin.debugger", "pywin.debugger.dbgcon","pywin.dialogs",
                                       "pywin.dialogs.list","Tkconstants","Tkinter","tcl"],

                            }},
    #these are the data files like templates, site media and admin media
    data_files = [(".",["sol.db"]),
        ("templates",glob.glob("templates\*.*")),
        #("files",glob.glob("files\*.*")),
        ("media",glob.glob("media\*.*")),
        ("media\css",glob.glob("media\css\*.*")),
        ("templates\admin",glob.glob("C:\Python25\Lib\site-packages\django\contrib\admin\templates\admin\*.*")),
        ("templates\admin\auth\user",glob.glob("C:\Python25\Libsite-packages\django\contrib\admin\templates\admin\auth\user\*.*")),
        ("templates\admin_doc",glob.glob("C:\Python25\Lib\site-packages\django\contrib\admin\templates\admin_doc\*.*")),
        ("templates\widget",glob.glob("C:\Python25\Lib\site-packages\django\contrib\admin\templates\widget\*.*")),
        ("templates\registration",glob.glob("C:\Python25\Lib\site-packages\django\contrib\admin\templates\registration\*.*")),
        ("adminmedia\css",glob.glob("C:\Python25\Lib\site-packages\django\contrib\admin\media\css*.*")),
        ("adminmedia\js",glob.glob("C:\Python25\Lib\site-packages\django\contrib\admin\media\js\*.*")),
        ("adminmedia\img",glob.glob("C:\Python25\Lib\site-packages\django\contrib\admin\media\img\*.*")),
        ],
    zipfile = None,
    console=['sol.py'],
    )</pre>
<p>This is the build script.</p>
<pre>python -OO setup.py py2exe --b 2 --optimize 2 --dist-dir y:sol
rd /s /q build</pre>
<p>You can download the demo from <a href="http://code.google.com/p/s-o-l/" target="_blank">code.google.com</a>. I&#8217;ll keep updating these scripts as I learn more. So get the updated scripts from <a href="http://code.google.com/p/s-o-l/" target="_blank">code.google.com</a>.</p>
<p>If you are to engage in such a exercise, you need lot of patience.</p>
<p>Next steps:</p>
<ul>
<li>Integrate with UPX</li>
<li>Integrate with Inno Setup (or some other windows setup makers)</li>
</ul>
<p>I&#8217;m sure this can be done in a better way. Feel free to comment.</p>
<p>Reference:</p>
<ul>
<li><a href="http://www.silverstripesoftware.com/blog/archives/51" target="_blank">Deploying a Django app on the desktop</a></li>
<li><a href="http://jjude.com/2008/04/make-your-django-application-as-a-stand-alone-desktop-application/" target="_blank">My frustration with packaging django</a></li>
<li><a href="http://www.eflorenzano.com/blog/post/hosting-django-site-pure-python/" target="_blank">Hosting a Django Site with Pure Python</a></li>
<li><a href="http://www.py2exe.org/" target="_blank">Py2exe</a></li>
</ul>
<h4  class="related_post_title">Related Posts:</h4><ul class="related_post"><li><a href="http://www.jjude.com/2008/08/s-i-p-goes-online/" title="S-I-P goes online">S-I-P goes online</a></li><li><a href="http://www.jjude.com/2008/07/understanding-django-template-tags/" title="Understanding Django Template Tags">Understanding Django Template Tags</a></li><li><a href="http://www.jjude.com/2008/06/say-in-pixels-a-photoblog-in-django/" title="Say In Pixels &#8211; a photoblog in Django">Say In Pixels &#8211; a photoblog in Django</a></li></ul><p><a href="http://www.jjude.com/2008/04/make-your-django-application-as-a-stand-alone-desktop-application/">Django application as a stand-alone desktop application</a> is post from <a href="http://www.jjude.com">finally{}</a>.
<p>Author Bio : Joseph is an independent consultant helping organizations to achieve their business objectives through IT investment. You can follow him on twitter <a href="http://twitter.com/jjude">@jjude</a></p></p>]]></content:encoded>
			<wfw:commentRss>http://www.jjude.com/2008/04/make-your-django-application-as-a-stand-alone-desktop-application/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

