django choice field

Solutions on MaxInterview for django choice field by the best coders in the world

showing results for - "django choice field"
Jacob
12 Mar 2019
1First I recommend you as @ChrisHuang-Leaver suggested to define a new file with all the choices you need it there, like choices.py:
2
3STATUS_CHOICES = (
4    (1, _("Not relevant")),
5    (2, _("Review")),
6    (3, _("Maybe relevant")),
7    (4, _("Relevant")),
8    (5, _("Leading candidate"))
9)
10RELEVANCE_CHOICES = (
11    (1, _("Unread")),
12    (2, _("Read"))
13)
14Now you need to import them on the models, so the code is easy to understand like this(models.py):
15
16from myApp.choices import * 
17
18class Profile(models.Model):
19    user = models.OneToOneField(User)    
20    status = models.IntegerField(choices=STATUS_CHOICES, default=1)   
21    relevance = models.IntegerField(choices=RELEVANCE_CHOICES, default=1)
22And you have to import the choices in the forms.py too:
23
24forms.py:
25
26from myApp.choices import * 
27
28class CViewerForm(forms.Form):
29
30    status = forms.ChoiceField(choices = STATUS_CHOICES, label="", initial='', widget=forms.Select(), required=True)
31    relevance = forms.ChoiceField(choices = RELEVANCE_CHOICES, required=True)
32Anyway you have an issue with your template, because you're not using any {{form.field}}, you generate a table but there is no inputs only hidden_fields.
33
34When the user is staff you should generate as many input fields as users you can manage. I think django form is not the best solution for your situation.
35
36I think it will be better for you to use html form, so you can generate as many inputs using the boucle: {% for user in users_list %} and you generate input with an ID related to the user, and you can manage all of them in the view
queries leading to this page
how to use model choice field in forms in djangodjango choice field textdjango docs choicefieldcreating a django choicefieldcreate django choice field based on modelchoicefield django exampledjango model choice fielddjango choice field in templatechoice in djangopdjango list choice fieldhow to fill a choicefield 28 29 djangofield choice value in django formsdjango form choicefield from listhow to write choice field in django modelsget choice field value djangochoicefield in django modelsuse model value as choice field in djangoforms choicefield djangoadding choice field in django modelchoice in model djangodjango choicefield displaydjango model choice field examplechoicefield in modelhow to use choice field in django modelsdjango choicedjango choice fieldsget choice field value in a list django modeldjango choicefield widgetchoicefield in form in djanodjango choice typedjango choice field labeldjango choice modelchoicefield django modeldjango choicefield modelformdjango choicefield from querysetchoice field django formdjango choice field from modeldjango create choicefield from modelhow to define select choice field models in djangodjango widget for choicefielddjango forms choicefield choiceschoice django formchoices field djangocreate choice field with choices djangochoicefield django formdjango form choicefield name choicesdjango choicefield from viewsimple sample choice field djangodjango choices fielddjango model choice field formdjango choice field model examplechoice in django modelsdjango form choice field valuechoice django widgetforms choicefield djangochoice from a django model field retrieve choice field djangoshowing a choice field in django formschoice in django modelmodel choice djangochoice model field djangpchoicefield django form exampledjango choice field threeforms choicefield django widgetdjango choice field exampledjango choice field modelchoicefield django modedjango choice field choices 22django filter 22 choice fieldwidget for choicefield django model formchoicefield djangohow to write choice field in djangoforms choice field djangodjango models choicefielddjango model form choice fielddjango form choicefield examplechoicefield widget forms djangodjango choicefield from modeldjango models choice fieldwhat is choice field in djangohow to use choice in django modelmodels choicefieldpip install django choicefieldattribute in choicefield djangodjango model choice field with all fieldsdjango form choicefield show django choicefield examplehow to make a choice field in models django choicefield django modelformmodel django choice fieldchoicefield django formschoicefield django model and databasechoice field in django modelsdjongo choicefielddjango field choicedjango choice filedlist choice fields in django formshow to get choice field value in djangodjango models choicehow to choicefield form i html code djangodjango form choicefieldmake choicefield 3d to django modeldjango choice field display in templatemodel choice field django exampledjango models choicefielddjango form choicefield from modelmaking choice field in django modelschoice field model djangodjango choice field with apiforms choicefield model form djangodjango choice field choices from dbchoicefield in djangochoice model in djangodjango model choicefielddjango choicefield tuplechoice field django modelsdjango choicefield templatechoice field in form djangodjango choicefield filter optionsdjango forms choicefielddjango choicefieldfilter choicefield django modelreturn full choice name choice field django modelsdjango choice field objectdjango choicefield choicesuse choice field models in jangodjango forms choicefielddjango choices field modelchoice widget django form pyhow to make choice field in djangochoice in djangodjango choice field filterchoice model djangochoice field in django formsusing choicefield in form in djangodjango choice firlddjango form choice fielddjango filter 21 3d choicefieldmodels choicefield djangodjango forms choice fielddjango render choicefieldform choice field djangodjango forms choicefield widgetchoice field type djangodjango choice field modelformwhat are the properties of choice fieldn django 3fchoice field in djago formsdjango form model choice fielddjango template choice field valuechoicefield django model show in htmltype choice field djangohow to give choice field in django formsdjango choice field formform choicefield djangochoice djangochoice field widget djangochoice field in django modeldjango choice field with querysetdjango choice input formschoicefield example djangodjango why choicefield as ulmodel choice field djangochoicefield models exampledjango choice field set choicesdjango text choice fielddjango choice field set choices in viewdjango choicefield modeldjango models choice optionsdjango filter choicefielddjango choice field only certain optionschoice field in template djangochoicefield django widgetho to choice filed in html display djangodjango choice field set choices in functionschoice filed in djangofield choice djangodjango form choice field querysetchoice django fielddjango modelform choicefieldchoice field view djangodjango field choicesdjango form choicefield attrschoice value djangomodels choice fielddjango choicefield otherdjango form choicefield modeldefine a choice from choices in djangodjango models choicedjango choice value on templatedjango forms where to set choices for choicefieldhow to add choice field in django modeldeclaration of choice field djangodjango choice tyoechoicefield django charfieldchoice field in djangodjango choice field form model examplechoice field how in djangochoicefield form djangochoice filed djangowidget choicefield form djangodjango choice fielddjango choicefield initialchoice field django in modelschoicefield django modelshow to use choicefield in form djangochoice limited djangochoicefield forms djangohow to use choice field in djangodjango choicefield in modelchoice field djangousing choicefield django modelchoice widget djangochoice field in template django show make choice in model djangohow to wokr with choicefield djangomodels choice field djangodjango choice field