django-forms

Django form - set label

I have a form that inherits from 2 other forms. In my form, I want to change the label of a field that was defined in one of the parent forms. Does anyone know how this can be done? I'm trying to do it in my __init__, but it throws an error saying that "'RegistrationFormTOS' object has no attribute 'email'". Does anyone know how I can ...

Can I override the html_name for a tabularinline field in the admin interface?

Is it possible to override the html naming of fields in TabularInline admin forms so they won't contain dashes? I'm trying to apply the knowledge obtained here to create a TabularInline admin form that has the auto-complete feature. It all works except that Django insists in naming the fields in a tabularinline queryset as something in...

HTML Forms without actions

In Django / Pinax, I've come across the login form which starts like this : <form class="login" method="POST" action=""> It works perfectly well. So I assume that either some java-script or something in the Django framework is putting the value into the action attribute. So my questions ; a) How does Django insert the action? b) Wh...

Using ModelForm and passing arguments

class MyUserAdminForm(forms.ModelForm): class Meta: model = Users group = forms.ModelMultipleChoiceField( queryset=Groups.objects.filter(domain__user=3), widget=forms.CheckboxSelectMultiple, ) class UserAdmin(admin.ModelAdmin): list_display = ('login', 'company', 'userType') form = MyUserAdminForm filter_horizontal = ('group',) a...

Django Forms, set an initial value to request.user

Is there some way to make the following possible, or should it be done elsewhere? class JobRecordForm(forms.ModelForm): supervisor = forms.ModelChoiceField( queryset = User.objects.filter(groups__name='Supervisors'), widget = forms.RadioSelect, initial = request.user # is there some way to make t...

Modify value of a Django form field during clean()

I am adding custom validation to my forms and custom fields in my Django app. I would like to be able to modify the value of a field when triggering an error. For example, if there is an error, the form should be redisplayed with the field value corrected by clean() and an error message "Data has been corrected below. Click save again to...

How do I process a complex graphical UI element in a django form?

I have a few complex GUI elements (like a custom calendar with many days that can be highlighted) that appear along with standard django form input fields. I want to process the data I/O from these complex forms along with the Django forms. Previously I would use AJAX requests to process these custom GUI elements on my HTML form after ...

splitting a ManyToManyField over multiple form fields in a ModelForm

So I have a model with a ManyToManyField called tournaments. I have a ModelForm with two tournament fields: pay_tourns = forms.ModelMultipleChoiceField( queryset=Tourn.objects.all().active().pay_tourns(), widget=forms.CheckboxSelectMultiple()) rep_tourns = forms.ModelMultipleChoiceField( ...

Django Forms, ModelChoiceField using RadioSelect widget, Grouped by FK

The challenge, output a radio select in nested <ul></ul>, grouped by the task fk. ie. class Category(models.Model): # ... class Task(models.Model): # ... category = models.ForeignKey(Category) # ... forms.py class ActivityForm(forms.ModelForm): # ... task = forms.ModelChoiceField( queryset = Task....

Django Python: Eval syntax for multiple fields created at runtime.

Hi there! My eval syntax isn't right. Namely, for each category, I'd like to output a ModelChoiceField named category_task, ie. if category were 'fun', then a radio select field 'fun_tasks' would be output. categories = Category.objects.all() for category in categories: eval(category)_tasks = form.ModelChoiceField( queryse...

django : using admin datepicker

I'm trying to use the admin datepicker in my own django forms. Roughly following the discussion here : http://www.mail-archive.com/[email protected]/msg72138.html I've a) In my forms.py included the line from django.contrib.admin import widgets b) and used the widget like this : date = forms.DateTimeField(widget=widget...

How do you change the default widget for all Django date fields in a ModelForm?

Given a set of typical models: # Application A from django.db import models class TypicalModelA(models.Model): the_date = models.DateField() # Application B from django.db import models class TypicalModelB(models.Model): another_date = models.DateField() ... How might one change the default widget for all DateFields to a cu...

How do you modify the default widget for all builtin form fields of a certain type in Django?

This is a follow-up on How do you change the default widget for all Django date fields in a ModelForm?. Suppose you have a very large number of models (e.g. A-ZZZ) that is growing with the input of other developers that are beyond your control, and you want to change the way all date fields are entered (i.e. by using jQueryUI). What's t...

Django Admin Template Overriding: Displaying checkboxselectmultiple widget

Have 2 tables Domain and Group having one to many relationship. These tables have many to many relationship with User table On the User admin interface I am rendering the Group and Domain as CheckboxSelectMultiple widgets. Is it possible to present this in a table form with 2 columns: Domain in one column and the list of groups belong...

django saving modelform with MultipleChoiceField

I'm using MySQL my table model : class Offer(models.Model): ... additional=models.CharField('Dodatkowe informacje',max_length="100",choices=ADDITIONAL_CHOICES.items(),blank=True) ... my form: class OfferForm(forms.ModelForm): additional=forms.MultipleChoiceField(label='dodatkowe informacje',choices=ADDITIONAL_CHOICES....

How can I make the Django contrib Admin change list for a particular model class editable with drop downs for related items displayed in the listing?

Basically I want to have an editable form for related entries instead of a static listing. ...

How would I disable the 5 same fields of specific forms in a formset?

Some of the forms represent parent objects and I want most field disabled in each of these forms, if they're for a 'parent' object. Is there an easy way to do this? ...

Django Imagefield not working properly via ModelForm

I'm certain I'm doing something really obviously stupid, but I've been trying to figure it out for a few hours now and nothing is jumping out at me. I'm using a ModelForm so I can expose a few fields from a model for editing. 2x ImageField, 1x TextField. The Form is processed and the TextField works. The two ImageFields do not work and ...

Populating form field based on query/slug factor

I've seen some similar questions, but nothing that quite pointed me in the direction I was hoping for. I have a situation where I have a standard django form built off of a model. This form has a drop down box where you select an item you want to post a comment on. Now I'd like people to be able to browse by items, and click a link to co...

forms.SelectMultiple from models.CommaSeparatedIntegerField

I have a model with field: class Movie(models.Model): genre = models.CommaSeparatedIntegerField(max_length=100, choices=GENRE_CHOICES, blank=True, default=0) lang = models.CommaSeparatedIntegerField(max_length=100, choices=LANG_CHOICES, blank=True, default=0) And I need to get multiple select fields (not checkboxes) from that....