I've been using Python for some time but I'm new to Django. In one of my 
pet projects to help me up the learning curve, I have a model defined thus:

class Program(models.Model):

     ratingChoices = (
         (1, 'Essential'),
         (2, 'Important'),
         (3, 'Nice to Have'),
         (4, 'Geeks Only'),
     )

     category = models.IntegerField(choices = categoryChoices)
     rating = models.IntegerField(choices = ratingChoices)
     name = models.CharField(max_length = 50)
     version = models.CharField(max_length = 15)
     description = models.TextField()
     mainURL = models.URLField(verify_exists = False)
     downloadURL = models.URLField(verify_exists = False)
     installerPath = models.FileField(upload_to = 'downloads')

This is part of a database of categorised software, the categories being 
1 for 'security', 2 for 'office apps', 3 for programming tools, etc.

I have a simple URL scheme such that '/category/1' pulls up all the 
security related apps, '/category/2' all the office apps and so on.

In the views.py function which deals with this table, I'm using a 
straightforward 'package_list = Program.objects.filter(category = 
thisCategory)' call to pull out the rows I'm interested in for a given 
category.

In addition, each application is rated according to the list defined in 
the 'ratingChoices' tuple in the class definition.

The part of my template which displays the information looks like this:

{% block content %}
         <!-- start of item content -->
         {% for package in package_list %}
         <!-- start section -->
         <tr><td>
         <div id="revtabs">
             <ul>
                 <li><a href="{{ package.downloadURL }}" 
rel="external"><span>Website</span></a></li>
                 <li><a href="{{ package.installerPath 
}}"><span>Install</span></a></li>
                 <li><a href=""><span>Rating: {{ package.rating 
}}</span></a></li>
             </ul>
         </div>
         <div class="sectiontitle">
         <div class="itemheading">{{ package.name }} v{{ package.version 
}}</div>
         {{ package.description }}
         </div>
         </td></tr>
         <!-- end section -->
         {% endfor %}
{% endblock %}

This all works as expected. The final step that I'm not able to figure 
out is what to put in either the view or the template so that I can do a 
lookup of the 'package.rating' value (which will be 1, 2, 3 or 4) 
against the 'ratingChoices' data so that the final output shows 
something like 'Rating: Important' rather than 'Rating: 2'.

I'd thought of putting these ratings into their own table, although this 
seems a bit of a waste for a short list of data points that will never 
change.

Any help or advice greatly appreciated.

-- 

Regards

Phil Edwards   |  PGP/GnuPG Key Id
Brighton, UK   |  0xDEF32500


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to