<?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 foo &#187; required</title>
	<atom:link href="http://www.djangofoo.com/tag/required/feed" rel="self" type="application/rss+xml" />
	<link>http://www.djangofoo.com</link>
	<description>Django Tips and Tweaks</description>
	<lastBuildDate>Wed, 18 Aug 2010 09:38:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Display asterisks for required fields in template</title>
		<link>http://www.djangofoo.com/1/asterisks-for-required-fields-in-template</link>
		<comments>http://www.djangofoo.com/1/asterisks-for-required-fields-in-template#comments</comments>
		<pubDate>Mon, 11 Jan 2010 15:44:51 +0000</pubDate>
		<dc:creator>Davo</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[asterix]]></category>
		<category><![CDATA[field]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[required]]></category>

		<guid isPermaLink="false">http://www.djangofoo.com/?p=1</guid>
		<description><![CDATA[If you want to display simple asterisks (*) for required fields in Django then the following code is for you. The trick is to access the field properties inside the template and make a conditional statement. Here is a simple example of view and template: # this is inside your views.py def do_something(request): """Display simple [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to display simple asterisks (<strong>*</strong>) for required fields in Django then the following code is for you.<br />
The trick is to access the field properties inside the template and make a conditional statement.<br />
Here is a simple example of <strong>view</strong> and <strong>template</strong>:</p>
<pre class="brush: python">
# this is inside your views.py
def do_something(request):
      """Display simple form"""
      form = MyForm() # this will be used in the template.
      return render_to_response('template.html', locals())

# this is inside your template.html
<form action="somewhere" method="post">
   {% for field in form %}
      {{ field }} {% if field.field.required %}(*){% endif %}
   {% endfor %}
</form>
</pre>
<p>The <a href="http://docs.python.org/library/functions.html#locals" target="_new">locals()</a> function is a built in python function</p>
]]></content:encoded>
			<wfw:commentRss>http://www.djangofoo.com/1/asterisks-for-required-fields-in-template/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

