django version : 1.3.7 python version :2.6
model.py
CHOICES = (('Hospital','Hospital'),("Doctor's office", "Doctor's office")) place_of_first = models.CharField(max_length=100, default=None, choices=CHOICES, blank=True, null=True, verbose_name="")
form.py
class Form(ModelForm): def __init__(self, *args, **kwargs): super(Form, self).__init__(*args, **kwargs) self.fields['creation_date'].widget.attrs['readonly'] = True required_css_class = 'required' class Meta: model = MODELFORM widgets = { 'place_of_first' : RadioSelect() }
its giving empty level with radiobutton like [ radioi button "------------------" ] i want to remove this level with radio button. its non-mandatory field.
score:1
i did face same issue. Update your forms.py file .
if self.fields['place_of_first'].widget.choces[0][0] == "" :
del self.fields['place_of_first'].widget.choices[0]
i hope it will work for you !!!
score:1
you're getting the dashes because you have blank=True
set in your model. Try switching it to blank=False
.
Here's some info from the Django site:
Unless blank=False is set on the field along with a default then a label containing "---------" will be rendered with the select box. To override this behavior, add a tuple to choices containing None; e.g. (None, 'Your String For Display'). Alternatively, you can use an empty string instead of None where this makes sense - such as on a CharField.
Credit To: stackoverflow.com
Related Query
- Remove empty level in django model form
- Override Django formset delete behavior: Delete form instance if empty field in Django model formset
- Dynamically remove an exclusion on a field in a django model form
- Django - Empty admin form of Model
- Automatic creation date for Django model form objects?
- Create empty queryset by default in django form fields
- Django required field in model form
- Why does Django Rest Framework discourage model level validation?
- Can I have a Django form without Model
- Django Admin- disable Editing and remove "Save" buttons for a specific model
- How to get Django form field from model field?
- How can I disable a model field in a django form
- How do I construct a Django form with model objects in a Select widget?
- Django model field validation without a custom form
- Display a boolean model field in a django form as a radio button rather than the default Checkbox
- How do I add custom actions to a change model form in Django Admin?
- Conditionally Require Only One Field In Django Model Form
- Add dynamic field to django admin model form
- How do I remove a model but keep the database table on Django
- DateTime field in Django form model
- Remove password from custom Django User model
- Django Form Wizard to Edit Model
- Django unique model fields validation in form
- How to use custom form fields for model fields in the Django admin?
- process the media class of a model form in django to a template
- Django Form request.POST.get() always returns empty
- How to remove username field in the register form on django admin?
- How To Update Existing Profile Django Model Form
- Django - Remove "Currently" In An Image Edit Form and Replace It With The Actual Image
- Use Model Property in a Django Model Form
More Query from same tag
- django-rest-framework limit the allowed_methods to GET
- What's the proper way to add Microdata (for Schema.org VideoObject) to a page in my Django app?
- Where is a django validator function's return value stored?
- Django : OneToOneField - RelatedObjectDoesNotExist
- How to csrf_token protection in jinja2 template engine?
- How do i cast char to integer while querying in django ORM?
- create virtual environment for Python 3.4-Django 1.7 in Windows with another vers of Python installed
- Heroku celery background task
- Reusing old options from pagination and filter Django
- Hide a specifc field in update but not in create
- Global Exception Handling in Django-rest-framework
- Correct way to count for a foreign key model in Django template
- Amazon EC2 Django Static Files configuration
- Setting points for an object in pinax-points
- How to allow only one row to have a specific field value?