Questions tagged [choicefield]

202 questions
3
votes
1 answer

Some Django ChoiceFields with the same choice source

I have a model like this: class MyModel(models.Model): DAYS = ((str(d), str(d)) for d in range(1, 29)) day1 = models.CharField('Day 1', max_length=3, null=True, blank=True, choices=DAYS) day2 = models.CharField('Day 2', max_length=3,…
baldr
  • 2,891
  • 11
  • 43
  • 61
3
votes
2 answers

Symfony2 DataTransformer for choice field

I'm trying to create a custom choice list field. And almost all seems working, except the preselected values on the edit part. Basically i'm creating a mixed list field with multiple object type (the backend is mongodb), i know that is a dirty way…
m47730
  • 2,061
  • 2
  • 24
  • 30
3
votes
1 answer

how to set a value for choicefield in django

I have a address form which has a choicefield of countries. I want to set a value before the form loads. How could I do that? Here is the form: from django import forms from django.utils.translation import gettext as _ from django_countries import…
Maverick
  • 2,738
  • 24
  • 91
  • 157
3
votes
1 answer

Customizing RadioSelect

Hello I have a form with ChoiceField whose widget is set to RadioSelect Now to override default html output one needs to subclass RadioFieldRenderer like this: class SimpleRadioFieldRenderer(forms.widgets.RadioFieldRenderer): def render(self): …
Kugel
  • 19,354
  • 16
  • 71
  • 103
3
votes
2 answers

Add an "empty" option to a ChoiceField based on model datas

I'm defining a ChoiceField based on a model's datas. field = forms.ChoiceField(choices=[[r.id, r.name] for r in Model.objects.all()]) However I'd like to prepend my options with an empty one to select "no" objects. But I can't find a nice way to…
Damien MATHIEU
  • 31,924
  • 13
  • 86
  • 94
3
votes
1 answer

Django: Using a raw query to limit a foreignkey choicefield in a ModelForm

Taking a classic foo bar example: In models.py: Class Foo(models.Model): name = models.CharField(max_length= 200) Class Bar(models.Model): name = models.CharField(max_length= 200) foo = models.ForeignKey('Foo') In my form, I tried to…
2
votes
4 answers

I need to add a choice field to sharepoint that has values depending on the current selection

I need to add a choice field to sharepoint that has values depending on the current selection. Example: if the current selection is Open then the options have to be 'open, and In progress **Current selection | Possible selections** Open …
MichaelD
  • 8,377
  • 10
  • 42
  • 47
2
votes
1 answer

django Choice list (dynamic choices)

i have a choices list : CATEGORY_CHOICES = ( ("T-shirts", "T-shirts"), ("Hoodies", "Hoodies"), ("Shorts", "Shorts"), ) but i want to make this list dynamic so i can add and delete choices ,i created a new model Category what i want to do is…
NAS
  • 188
  • 11
2
votes
2 answers

Python dataclass to implement choice type

I have a set of dataclasses say: from dataclasses import dataclass, asdict, InitVar @dataclass class Item: name: str = None identifier: int = None @dataclass class Container: item: Item …
user642770
  • 415
  • 5
  • 18
2
votes
1 answer

How to provide choices to django rest framework DecimalField serializer?

Django==2.2.6 djangorestframework==3.10.3 Models.py VAT_CHOICES = [(Decimal('0.00'), '0%'), (Decimal('6.00'), '6%'), (Decimal('12.00'), '12%'), (Decimal('25.00'), '25%')] class Service(models.Model): vat =…
Apon
  • 152
  • 1
  • 3
  • 12
2
votes
1 answer

Django: forms.ChoiceField, overriding forms __init__

I am trying to implement a forms.ChoiceField() with values from a view. I already can do it if I declare the choices in the forms.py, but that's not what I need. views.py: def add_crime(request): values =…
2
votes
2 answers

Django ValidationError after javascript modifies the choice field

I'm working on a job scheduling app for a REST API and I've created a Tasks, Nodes, URL, Adom, BaseOptions, and Jobs tables in Django. The BaseOptions have a foreign key for src_adom and dst_adom and the Jobs have foreign keys for the Task,…
2
votes
1 answer

Symfony2.3 setting value and innerHTML of a choicefield from a query

From a query I'm trying to personalize the choice field. this is how I get the content of the select: $em = $this->getDoctrine()->getManager(); $query2 = $em->createQuery("SELECT p.id,p.nombre FROM Exppromociones p"); $productos =…
Javier Heisecke
  • 1,162
  • 1
  • 11
  • 28
2
votes
2 answers

Django template - get object's choice field text

This is my model: class Person(models.Model): ... DOP = 1 PPP = 2 contract_choices = ( (DOP, 'always'), (PPP, 'sometimes'), ) contract = models.CharField(max_length=3, choices = contract_choices) ... I…
Ljubisa Livac
  • 819
  • 3
  • 13
  • 38
2
votes
2 answers

In Django, remove options in a choice-field based on other fields in a model

I'm new to Django and any help is appreciated, How can I restrict the choice option in one field based on a previous field. For example, if I select 'dog' for animal, I want to remove 'chocolate' from the FOOD_CHOICE, because I love dogs. Thanks!!!…
Juan
  • 477
  • 4
  • 8
1 2
3
13 14