choicefield

Django template – get object's choice field text

Django template – get object's choice field text Question: This is my model: class Person(models.Model): … DOP = 1 PPP = 2 contract_choices = ( (DOP, ‘always’), (PPP, ‘sometimes’), ) contract = models.CharField(max_length=3, choices = contract_choices) … I need contract field value in my template: {% for person in persons %} {{ person.get_contract_display }} {% …

Total answers: 2

Django ChoiceField

Django ChoiceField Question: I’m trying to solve following issue: I have a web page that can see only moderators. Fields displayed on this page (after user have registered): Username, First name+Last name, Email, Status, Relevance, etc. I need to display table with information of all users stored in db with this fields, but two of …

Total answers: 4

How to get the label of a choice in a Django forms ChoiceField?

How to get the label of a choice in a Django forms ChoiceField? Question: I have a ChoiceField, now how do I get the label when I need it? class ContactForm(forms.Form): reason = forms.ChoiceField(choices=[("feature", "A feature"), ("order", "An order")], widget=forms.RadioSelect) form.cleaned_data["reason"] only gives me the feature or order values or so. Asked By: webjunkie || …

Total answers: 10