<?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; model</title>
	<atom:link href="http://www.djangofoo.com/tag/model/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>Change Django Auth User Meta</title>
		<link>http://www.djangofoo.com/271/change-django-auth-user-meta</link>
		<comments>http://www.djangofoo.com/271/change-django-auth-user-meta#comments</comments>
		<pubDate>Thu, 29 Apr 2010 13:26:35 +0000</pubDate>
		<dc:creator>Arif Harbott</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[models]]></category>

		<guid isPermaLink="false">http://www.djangofoo.com/?p=271</guid>
		<description><![CDATA[Sometimes it can be helpful to change the default behaviour of the Auth User model or other models built into Django. One use case might be if you want to change the length of the username field in the Auth User model to allow for longer usernames (e.g. an email address). There is a simple [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it can be helpful to change the default behaviour of the <strong>Auth User model</strong> or other models built into Django.<br />
One use case might be if you want to change the length of the username field in the Auth User model to allow for longer usernames (e.g. an email address).</p>
<p>There is a simple way to change the max length attribute:</p>
<pre class="brush:python">from django.contrib.auth.models import User
User._meta.get_field_by_name('username')[0].max_length=75
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.djangofoo.com/271/change-django-auth-user-meta/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get/List model fields</title>
		<link>http://www.djangofoo.com/80/get-list-model-fields</link>
		<comments>http://www.djangofoo.com/80/get-list-model-fields#comments</comments>
		<pubDate>Mon, 22 Feb 2010 14:39:11 +0000</pubDate>
		<dc:creator>Davo</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[fields]]></category>
		<category><![CDATA[get fields]]></category>
		<category><![CDATA[list fields]]></category>
		<category><![CDATA[meta fields]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://www.djangofoo.com/?p=80</guid>
		<description><![CDATA[It is possible to get/list all of the fields for the given model, to do so you need to access the _meta attribute of the Model. The following example demonstrates how to do it. # in the models.py class Car(models.Model) year = models.IntegerField() name = models.CharField(max_length=50) ... def get_fields(self): # make a list of field/values. [...]]]></description>
			<content:encoded><![CDATA[<p>It is possible to get/list all of the fields for the given model, to do so you need to access the <strong>_meta</strong> attribute of the Model.<br />
The following example demonstrates how to do it.</p>
<pre class="brush: python">

# in the models.py
class Car(models.Model)
    year = models.IntegerField()
    name = models.CharField(max_length=50)
    ...

    def get_fields(self):
        # make a list of field/values.
        return [(field, field.value_to_string(self)) for field in Car._meta.fields]
</pre>
<p>Now that we implemented the get_fields function for our Car model, we can use this in the template&#8230;</p>
<pre class="brush: python">
# your template file...
# I assume that the variable 'car' is an instance of Car object.
{% for field, value in car.get_fields %}
    {{ field }} : {{ value }}
{% endfor %}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.djangofoo.com/80/get-list-model-fields/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

