Django choices and dictionary
<p>I have code</p>

<pre><code>JOBS = 1
CATEGORY_CHOICES = ((JOBS, "Jobs"),)
</code></pre>

<p>And code in the model</p>

<pre><code>category = models.IntegerField(choices=CATEGORY_CHOICES, default=JOBS)
</code></pre>

<p>Instead of "jobs" I want to add a dictionary and have access to it in the template. For example</p>

<pre><code>JOBS = 1
CATEGORY_CHOICES = ((JOBS, {'title':"Jobs",'icon':"fa fa-briefcase",'slug':"jobs"}),)
</code></pre>

<p>But instead I get the following</p>

<p><a href="https://i.stack.imgur.com/Oc7Jw.png" rel="nofollow"><img src="https://i.stack.imgur.com/Oc7Jw.png" alt="enter image description here"></a></p>

<p>How to add the dictionary into the choices?
I was able to create a model, which would be set up: title and icon. But instead, I decided to create a choice. Title I can add, but for the selected item to set the icon?</p>

<p>I would comment, but sadly not enough rep. The way <a href="https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.IntegerField" rel="nofollow">IntegerField</a> is setup, it displays the dictionary value and returns the dictionary key.</p>

<p>What it seems you want to do is have that key determine the results of several other values. What you should do then is in whatever view you submit that form to, set those other values based on the key returned by your IntegerField.</p>

<p>In other words:</p>

<pre><code>CATEGORY_CHOICES = ((1, 'Jobs'),(2, 'Cities'),)
</code></pre>

<p>Then later in the class or view that this form is submitted to:</p>

<pre><code>if CATEGORY_CHOICES  == 1:
    title = 'Jobs'
    icon = 'fa fa-briefcase'
    slug = 'jobs'
elif CATEGORY_CHOICES == 2:
    title = 'Cities'
`   icon = 'fa fa-city'
    slug = 'cities'
</code></pre>

python django dictionary