<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users1925</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/1925" rel="self"/>
  <title>clickpass.com/public/issac.kelly</title>
  <updated>Tue Feb 09 19:20:50 -0800 2010</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code1174</id>
    <published>2010-02-09T19:20:50-08:00</published>
    <updated>2010-03-02T18:48:09-08:00</updated>
    <title>[Python] Create a Dict from a Model</title>
    <content type="html">&lt;p&gt;This is a snippet to create a dict from one of my models.
&lt;br /&gt;I think that setting_context could be generated much more easily than what I'm doing here, just from reading about the different list and object comprehension functions, but I don't fully understand how to use them.&lt;/p&gt;

&lt;pre&gt;from django.db import models

# Create your models here.
class Setting(models.Model):
	description = models.CharField( max_length=256, blank=True )
	name = models.SlugField()
	value = models.CharField( max_length=128 )
	
	def get_context():
		settings = Setting.objects.all()
		settings = list(settings)
		setting_context = {}
		for setting in settings:
			setting_context[setting.name] = setting.value
		return setting_context&lt;/pre&gt;</content>
    <author>
      <name>clickpass.com/public/issac.kelly</name>
      <email>no-email@refactormycode.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1174-create-a-dict-from-a-model" rel="alternate"/>
  </entry>
</feed>

