A Django form field used for representing model relationships
Questions tagged [modelchoicefield]
86 questions
1
vote
2 answers
How to get help_text on a custom Django ModelChoiceField
I'm creating a custom ModelChoiceField so I can display custom labels for my foreign key, but in doing so Django no longer displays the help_text on the form. How can I get the help text back?
models.py
class Event(models.Model):
title =…

43Tesseracts
- 4,617
- 8
- 48
- 94
1
vote
1 answer
ModelChoiceField in conjuction with ModelForm
I want the user to be able to select a Solar Collector type from a dropdownlist. At this point the user is able to select two collector types from the dropdownlist in the SystemUpdateView() but however this value is apparently not stored into the…

arne
- 225
- 5
- 18
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
1
vote
0 answers
Djaongo: ModelChoiceField and Widget - Could not display non-foreign key field
I want to create a select field that displays a list of records from a column that is not a foreign key. I am able to do it using
widget=ForeignKeyRawIdWidget(rel=Slum._meta.get_field('electoral_ward').rel
where 'electoral_ward' is a foreign key…

Abhijit Ghate
- 382
- 3
- 16
1
vote
0 answers
django choicefield not working well on python 3.6
I have a form page with some choice fields in it. On my local machine with python 3.4.3, the choice fields are working very well. On python 3.6.3, the choice fields are listing the choices but;
1. the choices are listed horizontally
2. the choices…

LORD MILA
- 23
- 1
- 6
1
vote
2 answers
How to filter a model through multiple forms?
I have a single Car model which I'd like to filter through interdependent ModelChoiceField's:
class Car(models.Model):
make = models.CharField(max_length=50)
model = models.CharField(max_length=50)
platform =…

steerr
- 151
- 2
- 4
- 13
1
vote
0 answers
Dynamic choices in admin inline for CharField
I have a model with a Charfield in which no choices are set. Now in the admin panel, in the inline admin in which I display this model, I want to present a dropdown with possibilities to fill in (where the choices need to be fetched dynamically and…

physicalattraction
- 6,485
- 10
- 63
- 122
0
votes
0 answers
Error in `choicemodelr()`: ! argument "directory" is missing, with no default
I hope your are well. I am estimating a hierarchical bayes choice model with ChoiceModelR. This is a long code that works perfectly except this chunck. Every time I run this chunck I get the error: Error in 'choicemodel()': ! argument "directory" is…

Constanza Avalos
- 1
- 1
0
votes
1 answer
Django field with foreignKey
I'm using Django v4.1 and have a foreignKey relationship I want to pull into a form.
The two models:
class Service(models.Model):
client = models.ForeignKey("Client", on_delete=models.SET_NULL, null=True)
# some other fields
and
class…

MikeiLL
- 6,282
- 5
- 37
- 68
0
votes
1 answer
Format data queryset result to use in form.ModelChoiceField queryset option
I have a project in Django, with data in a Postgres database.
I want to create a form with a ModelChoiceField where I can select the data obtained in a previous queryset.
When I make the queryset to get data from the database:
list_result_queryset =…

garvarma
- 13
- 1
- 4
0
votes
1 answer
django adding extra data to IntegerChoices
I need to add extra data to enum Class IntegerChoice in django. I have carefully read the answer here How to add extra data to TextChoices? but it does not seem to work.
the definition of my enum type is :
class FabricType…

piscvau
- 33
- 1
- 3
0
votes
1 answer
Django limit records (options) for ModelChoiceField
I have a Model Reader with ModelChoiceField favourite_book which is a Foreign key. It is a DropDown menu and user can choose one from 40.000 possible options (records in the database).
There is a problem when editing this Model object and this…

Ljubisa Livac
- 819
- 3
- 13
- 38
0
votes
0 answers
How to dynamically filter a ModelChoiceField - Django
I am very new very mew to django... I am trying to filter the ModelChoiceField in my 'Detalle_ordenForm' so that it only shows the 'pacientes' (patients in english) that belong to a particular 'propietario' (owner in english)
my models are (only…

RBM
- 1
0
votes
0 answers
Passing CHOICES to as an ID to template
As you can see the photo above, I have displayed all "CATEGORY_CHOICES" (in forms of (Groceries, Groceries) in category.html.
views.py
def category(request):
context = {'CATEGORY_CHOICES': Category.CATEGORY_CHOICES}
return render(request,…

Jae
- 47
- 5
0
votes
0 answers
Django ModelChoiceField with custom queryset not validating
My ModelChoiceField is not validating saying that the selected choice is not an instance.
I am passing a custom queryset to my modelChoiceField that uses a custom manager (objects_sys) to return extra entries that are archived and do not normally…

Mustafamond77
- 330
- 2
- 15