Questions tagged [choicefield]
202 questions
1
vote
0 answers
Using Django ChoiceField gives a Value Error
I try to create dynamic choice. I fill choices with unit_list. Data to unit_list
loading from API (units). I set the choices dynamicly in the constructor. But when I try to save a new form, it gives 'value error'.
Have a nice day.
class…

Feyza Kılıç
- 21
- 2
1
vote
1 answer
DRF dynamic choices depend on current user
is there any way to make choices dynamically depend on current user
something like that:
class RideSerializer(serializers.ModelSerializer):
provider_username = serializers.ChoiceField(choices=request.user.providers)

usama Shehab
- 29
- 6
1
vote
1 answer
Django form don't validate : "Select a valid choice. 20 is not one of the available choices"
I have a form composed of 2 ChoiceField and a CharField. The second ChoiceField is populated via ajax when an item of the first one is selected.
The template populating it is the following :
{% for a in assets %}

Johanna
- 1,343
- 4
- 25
- 44
1
vote
0 answers
How to show choice field in template form
I want to show the Django choice field from Model on the HTML template like in the following picture. I can't see anything after doing this code.
models.py
class Author(models.Model):
TITLE_CHOICES = [
('MR', 'Mr.'),
('MRS',…

Prosenjit
- 241
- 5
- 15
1
vote
2 answers
Symfony 5 - Form - Choice value
I want to make a form with a select field that displays different options.
Those options are a list of NomenclatureDTO object field $libNom set as:
class NomenclatureDTO
{
public int $idNom;
public string $libNom;
public string…

Zabon
- 241
- 2
- 18
1
vote
2 answers
Django ChoiceField: Fail to access choices in template
after trying for hours I m frustrated with this. I just can't loop over my ChoiceField's choices in the template. It will not even enter the loop. But if I access the form field with pdb it looks fine.
my form:
MODE_CHOICES = (('blue', 'blue'),…

user234324
- 11
- 2
1
vote
1 answer
In Django forms.ModelChoiceField HOWTO restrict displayed choices but set one of the restricted values during cleanup
I have a custom field which subclasses ModelMultipleChoiceField. I provide the choices to be displayed via queryset parameter. This queryset excludes certain values. My problem comes when during cleanup operation for some workflows I need to select…

Chantz
- 5,883
- 10
- 56
- 79
1
vote
0 answers
why overwriting the init function of forms makes form fields return none
hey Im new to django and i need help i have a form that has two fields one of them is a choicefield and the choices attribute gets its data from views but the problem is when i call the form both fields return none
here is my forms.py
class…

Mo Zanganeh
- 11
- 1
1
vote
1 answer
How i can to relate 2 Django ChoiceFileds
I have a problem in my project.
I want to create a ChoiceField to be categories and subcategories in the models.py file. Well, it must be that I chose the first choice and the second according to the index of the place. For example, like the car…

Vusal Heyderli
- 41
- 3
1
vote
1 answer
Can't get initial value as modelchoicefield in django form
I have a column list. I'm trying to update one row from that list. After i select a row, i am trying to update it. After i select a row, i get one of the parameters which is table_id. table_id is defined in model.py and forms.py . I show that…

acaiberry
- 31
- 1
- 1
- 10
1
vote
0 answers
Symfony4.3 Sorting preferred choices provided by query builder in EntityType
I have a selection of events provided by query builder. All entities have to be shown in the selection field, using the future events as preferred choices. Both parts should be sorted by date (asc).
Till now it worked fine the following…

Flo
- 11
- 1
1
vote
2 answers
How can I search the choice field using display name?
I want to query the item from the database using django SmallIntegerField. The code I used is
Here is the class defination:
class Equipment(models.Model):
asset_status = (
(0, 'online'),
(1, 'offline'),
(2, 'unknown'),
…

Elegant Lin
- 25
- 2
- 10
1
vote
1 answer
Too many values to unpack (expected 2) Django
I am creating a form that contains a ChoiceField to which I establish the values of choice by means of view.
According to Django documentation ChoiceFields Choices the election values must be:
Either an iterable (e.g., a list or tuple) of 2-tuples…

scafrs
- 443
- 8
- 20
1
vote
1 answer
How can i pass custom object to form using Django
I am new to django, I created my custom user(auth_user) model. I need to create student registration form using custom user model according to my custom object
I have two models Title, User like this:
from django.db import models
#from…

somesh
- 528
- 2
- 10
- 26
1
vote
0 answers
Django & modelChoiceFields : populate my model choice field with one of two models
I have a modelChoiceField field1, when I Choose one of its choices, another modelChoiceField field2 is updated with data.
My problem is, this data can be a model1 type data or model2 type data.
and since I have this…

Elroum
- 327
- 1
- 3
- 18