A Django form field used for representing model relationships
Questions tagged [modelchoicefield]
86 questions
1
vote
1 answer
Django Question 'ModelChoiceField' object has no attribute 'use_required_attribute'
Dears,
I met a problem in Django.
There is an error about 'ModelChoiceField' object has no attribute 'use_required_attribute' and I don't know where I made mistake.
My goal is to make my submit customizing form but I couldn't understand how CBV in…

Ezra Lin
- 87
- 9
1
vote
1 answer
Django Choices Object Not passing id to URL
I'm using a model with a choices field that is being displayed by a form. I want to create a delete function in my views.py but can't get it to work. I suspect it's because my model object is not passing an id, or my url just isn't picking the…

user14593966
- 151
- 1
- 14
1
vote
1 answer
Django ModelFieldChoice select passing value
Hi i'm using ModelFieldChoice to set the foreign key from Provider in the model "Article" (Article belongs to Provider). The select in the template is displayed correctly with all the providers from the database, but when i try to post the form, it…

SebasEC
- 13
- 1
- 5
1
vote
1 answer
How to populate choices in second dropdown on the basis of selected value from first dropdown in Django using ModelChoiceFields for both dropdown
I have two dropdown:
Category
Sub Category
Both needs to be populated dynamically
Here I want to populate choices in sub_category on the basic of selected value from category field.
So i don't need to save the whole form.
class…

AMIT SINGH
- 11
- 1
1
vote
2 answers
Django ModelChoiceField is not filled when editing
I have ProjectForm form in which one field is ModelChoiceField with foreign key to Company Model. Creating new record and saving is not a problem, but when I want to edit that record this field is empy (like if none company was selected, but in DB I…

Tomas Trdla
- 1,142
- 1
- 11
- 24
1
vote
1 answer
Django / Customized ModelChoiceField: how label_from_instance works?
I use ModelChoiceField with initial value just for display (readonly field).
But value displayed is model id and I want to display customized value that will be a concatenation of 3 fields. I've override ____str____ method but it is not applyed.
I…

SLATER
- 613
- 9
- 31
1
vote
1 answer
Django Forms: How to create a simple dropdown list in a form using values from an existing model
I'm new to Django and struggling to find the best/correct way to populate a dropdown list in a ModelChoiceField within a form using a list I have stored in a database.
The basic code below works fine with my view passing the form as context to my…

blake
- 481
- 4
- 14
1
vote
0 answers
Django ModelChoiceField auto select views passed value
I have a simple problem with ModelChoiceField , I have a Classification class with four fields (name, price1, price2, price3) , I added an edit button and its working perfectly , i added the name on edit page as a ModelChoiceField , My problem is…

George
- 2,292
- 2
- 10
- 21
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
1 answer
Django ModelChoiceField queryset keeps returning same result regardless of input
I am trying to create a choicefield in a form which only contains those fields which relate to a previously selected option. So far on the site a user can select a parent option ( I Call discipline) and then submit at which time they are ask to…

Robert McLean
- 11
- 1
1
vote
2 answers
Multiple initial for checkbox rendered using widget-tweaks
I need guidance in selecting multiple initial values for checkbox which are rendered using widget-tweaks.
My code is working great when I have a single initial value. However when there is more than 1 initial value, only the first will be checked…

ragana
- 11
- 3
1
vote
1 answer
in forms.py when i set "to_field_name" to more than one column name, it's giving me error
I have created a label_form_instance for modelchoicefield but the values in html are showing primary key values. To get rid of that, i use to_field_names but i can't provide more than one column name in it.
class…

addminuse
- 23
- 4
1
vote
1 answer
Set Default value for a django ModelChoiceField
I need to set a default value for ModelChoiceField
The value is being sent from my views.py.
I've looked for some other similar questions but it didn't really help as it was all about ChoiceField with choices not a ModelChoiceField with queryset…

Ahmed Wagdi
- 3,913
- 10
- 50
- 116
1
vote
2 answers
how to store in the database the value of choicefiled in model using django
i have a form that allow user to enter a new record to the database by filling the text fields and choose one of the radio button.
the system work as it should and save the data of the text field except the radio button where its always empty. Yet…

Django Dg
- 97
- 4
- 19
1
vote
1 answer
Django ModelMultipleChoiceField gives me a ProgrammingError
I would like to get your help because I'm getting an issue which is a little bit weird to my mind.
I'm using Django 1.11.16
I have in my forms.py file this class :
class PublicationStatForm(forms.Form):
# publication_list =…

Essex
- 6,042
- 11
- 67
- 139