django choice field

First I recommend you as @ChrisHuang-Leaver suggested to define a new file with all the choices you need it there, like choices.py:

STATUS_CHOICES = (
    (1, _("Not relevant")),
    (2, _("Review")),
    (3, _("Maybe relevant")),
    (4, _("Relevant")),
    (5, _("Leading candidate"))
)
RELEVANCE_CHOICES = (
    (1, _("Unread")),
    (2, _("Read"))
)
Now you need to import them on the models, so the code is easy to understand like this(models.py):

from myApp.choices import * 

class Profile(models.Model):
    user = models.OneToOneField(User)    
    status = models.IntegerField(choices=STATUS_CHOICES, default=1)   
    relevance = models.IntegerField(choices=RELEVANCE_CHOICES, default=1)
And you have to import the choices in the forms.py too:

forms.py:

from myApp.choices import * 

class CViewerForm(forms.Form):

    status = forms.ChoiceField(choices = STATUS_CHOICES, label="", initial='', widget=forms.Select(), required=True)
    relevance = forms.ChoiceField(choices = RELEVANCE_CHOICES, required=True)
Anyway 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.

When 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.

I 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

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
django model choice field example widget choicefield form django ho to choice filed in html display django forms choicefield django choice field view django django choice fields how to ChoiceField form i html code django django forms where to set choices for choicefield field choice django django form choice field how to use model choice field in forms in django choice field in form django how to give choice field in django forms filter choicefield django model Django choice field in template model django choice field django choicefield from model forms choice field django django form choicefield show ------- django choice field display in template models.choicefield django django create choicefield from model django filter choicefield get choice field value in a list django model get choice field value django django docs ChoiceField django model form choice field choice from a django model field django choice field model example choice value django adding choice field in django model django form choicefield attrs django choice field text django choice firld make choice in model django django choice field three django render choicefield django field choices choice field in django model django choice field label field.choice value in django forms choice filed django django choice filed using choicefield django model choicefield django forms declaration of choice field django django models choice how to use choice in django model django choicefield other choice field widget django django list choice field django choice field modelform django choice field form django choice field form model example django choice field filter return full choice name choice field django models how to define select choice field models in django django form choice field value choice django how to write choice field in django models how to write choice field in django django choice field example django choicefield modelform choicefield django model and database choice in django django form choicefield from list django form choicefield model choice django form choice field django django models choice field models.choice field django forms choicefield choices django choicefield choices choicefield django models choice widget django choicefield form django list choice fields in django forms django template choice field value choicefield in django choice in django models django choice field choices django choice field choices from db django choicefield from queryset django modelform choicefield models.choicefield how to get choice field value in django pip install django choicefield how to add choice field in django model django choices field model choice field django form choice field in django forms django choice field object django choicefield filter options django choice field only certain options django choice input forms make choicefield = to django model choice field django models attribute in choicefield django django form choicefield from model widget for choicefield django model form models choice field django choices field django use choice field models in jango django text choice field django ChoiceField display choicefield django example choice field type django django forms choice field django model choice field form django model choice field with all fields choice field django in models choicefield in django models type choice field django choice field model django django forms choicefield widget making choice field in django models django form model choice field django choice model choice model field djangp how to use choice field in django django form choice field queryset creating a django choiceField django choicefield initial django choice field set choices in functions django choice field set choices in view django choice field set choices django choicefield tuple choicefield django model choicefield in model choicefield django charfield django choicefield model choice field in django models django models.choice django choice value on template django why choicefield as ul showing a choice field in django forms forms.ChoiceField model form django choice in django model choice model django django choice model choice field django simple sample choice field django django choice field model django filter != choicefield django forms.ChoiceField django forms choicefield choicefield django django choicefield widget django choicefield from view django choicefield example django models choicefield how to wokr with choicefield django django models.choicefield django model choice field choice field django django choices field choice field in django django choicefield django choice field
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source