Wow so easy (when you know where to look).
-- Thank you!
On Thursday, 9 October 2014 13:58:35 UTC+11, 6233114 6233114 wrote:
On Thursday, 9 October 2014 13:58:35 UTC+11, 6233114 6233114 wrote:
I am a newbie. I have searched the django docs for this answer, but I failed to find a reference, so here is my question.I have a select list as part of a form stored in my models.py file as a positiveintegerfield, as shown below:class AchievementDetails(models.Model, FillableModelWithLanguageVersi on): SELECT_ACHIEVEMENT_TYPE = 0ACADEMIC_ACHIEVEMENT = 1COMMERCIAL_ACHIEVEMENT = 2PERSONAL_ACHIEVEMENT = 3PROFESSIONAL_ACHIEVEMENT = 4SPORTING_ACHIEVEMENT = 5OTHER_ACHIEVEMENT_TYPE = 6ACHIEVEMENT_TYPES = ((SELECT_ACHIEVEMENT_TYPE, _('Select Type')),(ACADEMIC_ACHIEVEMENT, _('Academic Achievement')),(COMMERCIAL_ACHIEVEMENT, _('Commercial Achievement')),(PERSONAL_ACHIEVEMENT, _('Personal Achievement')),(PROFESSIONAL_ACHIEVEMENT, _('Professional Achievement')),(SPORTING_ACHIEVEMENT, _('Sporting Achievement')),(OTHER_ACHIEVEMENT_TYPE, _('Other Achievement Type')))....achievement_type = models.PositiveIntegerField(choices=ACHIEVEMENT_TYPES, default=SELECT_ACHIEVEMENT_ TYPE, validators=[MinValueValidator( 1)])
....In one of my templates I would like to display the text value of the achievement_type, but I can only get the number value of the users saved selection to be displayed.
Here is my views code, that returns only the numerical value of the users saved selection:def achievement_details(request):....for ad in achievement_details:ad.achievement_type_as_text = ad.achievement_type....How do I display the text value of the saved select list value?For example if the user has saved 2 as the achievement_type, how do I display Academic Achievement and not the number 2.I have tried the following line of code, but this only returns (2, )ad.achievement_type_as_text = AchievementDetails.ACHIEVEMENT_TYPES[ad. achievement_type]
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/862c0dc8-04e2-4bc4-9cc4-4212d549928c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment