Questions tagged [choicefield]
202 questions
2
votes
1 answer
Django access object attribute in choice form
I have a choice form, which allows user to choose employees with specific range assigned to them.
class ReservationBookingForm(forms.Form):
employee = forms.ModelChoiceField(
queryset = Employee.objects.none(),
#widget =…

gradle
- 113
- 2
- 11
2
votes
1 answer
How to combine django choice field with filepathfield
I want to process teplates with django. For that i need to use Choicefield and FilePathField.
I don't really know how to combine them. The Choice field in the form works as expected
class TaskBlockForm(forms.ModelForm):
""" form used for…

Marcel Hinderlich
- 213
- 1
- 3
- 19
2
votes
3 answers
Return display_name in ChoiceField
I'm implementing some REST API in DRF with ModelViewSet and ModelSerializer. All my APIs use the JSON format and some of my models use ChoiceField field, like that:
MyModel(models.Model):
KEY1 = 'Key1'
KEY2 = 'Key2'
ATTRIBUTE_CHOICES…

SimoV8
- 1,382
- 1
- 18
- 32
2
votes
1 answer
Django Choices: One of my choice items has the label copied over to the value
Very strange issue here. I'm using the django-choices module (v1.3), and defined a set of choices like so:
class BreaktimeChoices(DjangoChoices):
BREAKTIME_NONE = ChoiceItem(value=datetime.time(0,0), label=_('none'))
BREAKTIME_15_MIN =…

benwad
- 6,414
- 10
- 59
- 93
2
votes
1 answer
Validate choice list in Symfony2
I have a choice list where user can choose one value, but there I even set an empty value if the user doesn't select anything.
The form does not have model, to use @Assert annotation with it, and the choice field is optional, so in some case it will…

nowiko
- 2,507
- 6
- 38
- 82
2
votes
1 answer
Storing multiple checkbox values in database
I want to store multiple column values in table.Lets take a example .. What are your favourite colors? the choices can be red,blue,green, orange. So lets assume, the user selects atleast 2 values.
Is there any way to store the multiple values in…

Madjokr
- 147
- 2
- 16
2
votes
2 answers
List display names from django models
I have an object:
POP_CULTURE_TYPES = (
('SG','Song'),
('MV', 'Movie'),
('GM', 'Game'),
('TV', 'TV'),
)
class Pop_Culture(models.Model):
name = models.CharField(max_length=30, unique=True)
type =…

Ed.
- 4,439
- 10
- 60
- 78
2
votes
1 answer
Django form-wizard typechoicefield returning string instead of boolean
so i am using Django 1.3 form-wizard https://github.com/stephrdev/django-formwizard and i am running into problems with my typechoice field which is returning u'False' instead of just False (boolean).
What should i do?
ONE_OR_MULTIPLE_CHOICES = (
…

psychok7
- 5,373
- 9
- 63
- 101
2
votes
0 answers
Django CheckBoxSelectMultiple: individual checkbox initial values
For a given field, is it possible to have all boxes initially checked, but one?
Currently I am using: widget=forms.CheckboxSelectMultiple({'checked':'checked'}) to have all checkboxes initially checked. Is there a way to set this for each checkbox…

bsuire
- 1,383
- 2
- 18
- 27
2
votes
2 answers
Binding data to django's form choicefield
I have a simple form,
class Compose(forms.Form):
CHOICES = ()
recepient = forms.ChoiceField(choices=CHOICES)
subject = forms.CharField(max_length=100)
message = forms.CharField(widget=forms.Textarea)
Chocies are generated as…

user1349663
- 595
- 1
- 7
- 21
2
votes
2 answers
How to know how many items a choice field has inside the controller - Symfony2
I want to count the choice's items after the form has been created. The field is a simple Symfony's choice field with a query_builder to create the items. How can I achieve this?

Tales Santos
- 232
- 3
- 10
2
votes
1 answer
Need to add empty choice to existing valuelistqueryset for django choicefield
I need to add the empty choice value in existing valuelistqueryset for below choicefield in my form in Django similat to modelchoicefield("-------------"). Can anyone help me with this?
hardness =…

user1908622
- 41
- 4
2
votes
1 answer
django template ModelChoiceField length
I use the length tag in my template to count the number of items in my drop down list. The length is well displayed the first time the form is rendered. When the form is submitted and when the length has changed, the value is not updated but the…

rom
- 3,592
- 7
- 41
- 71
2
votes
1 answer
Use value for a ChoiceField in a template
I have something like this:
forms.py:
AVATAR_CHOICES = (('1','option1'), ('2','option2'), ('3','option3'),
('4','option4'))
class RegistrationForm(forms.Form):
avatar = ChoiceField(widget=RadioSelect, choices=AVATAR_CHOICES)
I'm passing form…

r_31415
- 8,752
- 17
- 74
- 121
1
vote
2 answers
listeners for ObjectChoice field
I am creating a BlackBerry application which contains two ObjectChoiceFields. I want to add listeners for each of them. I searched for that but did not find any of useful code.
It is like a country-state selector on websites. I am looking for…

Dil Se...
- 877
- 4
- 16
- 43