Questions tagged [modelchoicefield]

A Django form field used for representing model relationships

ModelChoiceField docs

86 questions
0
votes
1 answer

How to display a field from a modelchoice

I have a class in my forms and a object called tiposervico (ForeignKey). See bellow. In my template, after select a tiposervico I would like to display 'descricao' field on my screen. How can i do that? class servicoForm(forms.ModelForm): …
0
votes
1 answer

Django: How to get the list of the usergroups and use that list (dictionary) as a choice options for a model field?

Scenario: I have a field named "editor" in my model "Questions" as below: CHOICE_LIST = (('0', 'Undefined'), ('staffGroup', 'staffGroup'), ('staffGroup02', 'staffGroup02'), ('staffGroup03', 'staffGroup03'), ('staffGroup04', 'staffGroup04'),…
Mohammad
  • 657
  • 1
  • 7
  • 18
0
votes
1 answer

Django :How can I let my modelChoiceField take two possible types of models

I need to let a modelChoiceField have the possiblity of taking two different models objects. for example can billnum take as queryset: facture_ventes.objects or facture_depc.objects at the same time instead of only one model…
Elroum
  • 327
  • 1
  • 3
  • 18
0
votes
1 answer

Django: a modelChoiceField depend on another modelChoiceField

i have two ModelChoiceFields that are populated with database…
Elroum
  • 327
  • 1
  • 3
  • 18
0
votes
1 answer

Error : 'User' object has no attribute 'get' when trying to access current user in ModelForms for a ModelChoiceField dropdown

So below is the views.py and I'm trying to load a view with modelform. And within the modelform I need to load modelchoicefield depending on the current user logged in and tried the below solution(check forms.py.) When I run it, i get Attribute…
joelvarma
  • 150
  • 3
  • 17
0
votes
1 answer

Django ModelChoiceField model formset creating form for every object

I am trying to setup a model formset with a ModelChoiceField so that the user can create several forms and in each form they select one item from the queryset. However, when I render my formset, it is creating a form for each object in the queryset.…
lampwins
  • 920
  • 1
  • 9
  • 25
0
votes
2 answers

Get query results to group_by in model form and get placed in select

I have a model form and I'm trying to get a dropdown to populate the select with options from the database. My model form looks like this: class CreateTripsForm(forms.Form): start_locations =…
Hanny
  • 2,078
  • 6
  • 24
  • 52
0
votes
2 answers

Django ModelChoiceField, thousands of options , not user friendly

I have a ModelChoiceField in my form: customer = forms.ModelChoiceField(Customer.objects.all()) the problem is it renders as a drop down with hundreds of options and its difficult for users to find a customer, is there a way to overcome this???
Mani Shirvani
  • 188
  • 1
  • 8
0
votes
1 answer

Django ModelChoiceField with empty_label as valid input

I'm using the following form to generate a dropdown list with my registered users: class TaskAssignUserForm(forms.Form): user = forms.ModelChoiceField(queryset=User.objects.all().order_by('username')) Inside my template I render the above form…
aronadaal
  • 9,083
  • 1
  • 19
  • 33
-1
votes
1 answer

Django 3.1: Access objects in template of ModelChoiceField

Using Django 3.1 and I'm struggling with a basic tasks. I've got a form with a field like this: forms.ModelChoiceField(queryset=StorageSpace.objects.filter(visible=True), widget=forms.RadioSelect) I would like to do this in my view: {% for space in…
Remo
  • 1,112
  • 2
  • 12
  • 25
-2
votes
1 answer

Django MultiChoiceField form invalid

I asking for help sorting the reason for the form being invalid. In the application, Programmes run on specific dates, stored in the 'DAY' model. One or more Profs may be added to one or more days of a programme. In FORMS, I've filtered the…
William
  • 115
  • 1
  • 2
  • 12
1 2 3 4 5
6