Questions tagged [modelchoicefield]

A Django form field used for representing model relationships

ModelChoiceField docs

86 questions
0
votes
2 answers

How do I get rid of "Select a valid choice. That choice is not one of the available choices." error when using a ModelChoiceField?

I am trying to manually render options for a select filed in a django template. When I submit the form I get an error: "Select a valid choice. That choice is not one of the available choices." The error message also asks for required fields which I…
0
votes
1 answer

Django: Add a new value to ModelChoiceField

I have a ModelChoiceField in a form that uses a TextInput widget. I want to be able to select a value from the database or add new entries to the database with this input. If the value is not already in the database, I get an error on the form that…
ntf
  • 169
  • 1
  • 2
  • 17
0
votes
1 answer

Cannot assign "'": "" must be a "" instance. ModelChoiceField

I have a form where a user can select the title of an object and then save it but when I do hit save, I get an error. I am very certain that this problem is because I am using ModelChoiceField which returns ids of objects instead of the instances of…
0
votes
0 answers

Django. How to make ModelChoiceField work with SingleObjectMixin, FormView, and inlineformset_factory?

This shouldn't be hard How to show in a Django Model Form just the related records from Model.B for the user to choose. Ginven that it is provided the Model.A and Model.C data user is required to choose one from possible Model.B choices…
0
votes
0 answers

ModelChoiceField returns a number instead of its value

I have a simple model for my csv files: #models.py class csvModel(models.Model): csvFileName = models.CharField(max_length=50) csvFile = models.FileField(upload_to='tpData/csv/') My script allows a user to upload a file Then, I use a…
0
votes
2 answers

ModelChoiceField in django admin gives 'Select a valid choice. That choice is not one of the available choices.' error

Hej! I want a field in my django admin area where the user can select from given choices in the database. For example get a list of countries and choose one. But I will always get the ' Select a valid choice. That choice is not one of the available…
0
votes
1 answer

Filter fields queryset in Django ModelChoiceField with external reference keys

The Trim inherited the Car and the TrimType, and the TrimType inherited the Car. When creating Trim on a specific Car detail page, I want to filter the queryset of trimType field by the id of the Car. from All trimType select options to trimType…
JRR
  • 51
  • 1
  • 4
0
votes
1 answer

Django MultipleObjectsReturned error on form submit

I've got quite the mysterious MultipleObjectsReturned error that just popped up after weeks of not having an issue. I'm hoping is just something simple that I'm missing. I've got an Order model, an OrderLine model, which has an Item foreign key.…
0
votes
1 answer

How to structure a quiz in django using ModelChoiceField?

I am building an app using Django that will have a hard-coded quiz with 4 choices that users will fill out periodically. I am having trouble implementing this so that the user can fill out the form on one page and the instance is saved with relation…
Oleg
  • 31
  • 6
0
votes
1 answer

Django admin tabular inline lookup select dropdown box for a very large queryset

I have a django admin tabular inline, in which I have form = ProdForm which holds a modelchoicefield select box as follows; class ProdForm(forms.ModelForm): productid = forms.ModelChoiceField(queryset=Product.objects.filter(active=True), …
0
votes
1 answer

Django - can't get modelchoice FK while submitting form

I have a custom form form signup, referencing a "categorie" model on a modelChoiceField. As I try to submit it, it fails on getting the reference to the model and raises the following error : IntegrityError at /marketplace/signsupplier/ null value…
maxime
  • 11
  • 3
0
votes
1 answer

Django ModelChoiceField shows Customers objects(1) etc on list, how do i get it to show name of customers?

models.py class Customers(models.Model): Name = models.CharField(max_length=100) class Staff(models.Model): Name = models.CharField(max_length=100) class Cereals(models.Model): Name = models.CharField(max_length=100) Operator =…
Steve
  • 39
  • 5
0
votes
1 answer

Django set ModelForm ModelChoiceField initial value in UpdateView class

There are many related questions I checked on so before posting my own, but I still can't figure this out. Using Django 2.2.x. I want the owner field of my html form to initially display only 1 username and this username has to be the current event…
pastoreerrante
  • 143
  • 1
  • 11
0
votes
2 answers

UPDATE: Dynamic MultipleChoiceField changes instances to strings

I have a django form that has a multiple choice field. The field should be dynamic, that is, only the records associated with the user who is currently logged in should be displayed. I've managed to put this together so far; forms.py class…
The Voyager
  • 617
  • 9
  • 17
0
votes
1 answer

get_field_display() does not return string after saving it

Hereby my (simplified) situation. When I change a choicefield from one to the other, I want to record a message saying "Field changed from (previous) to (new)" In parenthesis I'd like the actual label of the field, so in case of the example below…
user1162541