django-forms

Django: How do I make fields non-editable by default in an inline model formset?

I have an inline model formset, and I'd like to make fields non-editable if those fields already have values when the page is loaded. If the user clicks an "Edit" button on that row, it would become editable and (using JavaScript) I would replace the original widgets with editable ones. I'd like to do something like this when loading t...

How do I validate a Django form containing a file on App Engine with google-app-engine-django?

I have a model and form like so: class Image(BaseModel): original = db.BlobProperty() class ImageForm(ModelForm): class Meta: model = Image I do the following in my view: form = ImageForm(request.POST, request.FILES, instance=image) if form.is_valid(): And I get: AttributeError at /image/add/ 'NoneType' object has...

Django forms: making a disabled field persist between validations

At some point I need to display a "disabled" (greyed out by disabled="disabled" attribute) input of type "select". As specified in the standard (xhtml and html4), inputs of type "select" can not have the "readonly" attribute. Note that this is for presentation purposes only, the actual value must end up in the POST. So here is what I do ...

Django MultiValueField - How to pass choices to ChoiceField?

I have a multivaluefield with a charfield and choicefield. I need to pass choices to the choicefield constructor, however when I try to pass it into my custom multivaluefield I get an error __init__() got an unexpected keyword argument 'choices'. I know the rest of the code works because when I remove the choices keyword argument from ...

dynamic django form

I am trying to use the dynamic django form script from http://www.djangosnippets.org/snippets/714/ The dynamic form is generated, but I am having hard time retrieving submitted fields through form.cleaned_data['myfield'] There are few comments on the snippet page, those didn't work either. ...

How to access a forms instance in a modelformset django

In my view I create a formset of photos belonging to a specific article, this works brilliantly, and I am able to render and process the forms. However for the image field I would like to display the already uploaded image. Normally I would access the path through the instance form.instance.image.get_thumbnail_url however that doesn't wo...

What is wrong with my django's model field ?

I am trying to do a PhoneField that convert the value as a standardized value. In this case, I want to use this clean method. def clean(self): phone = self.cleaned_data.get('phone') # Is it already standardized ? if phone.startswith('+'): mo = re.search(r'^\+\d{2,3}\.\d{9,11}$', phone) if not mo: raise...

Reusing Admin forms for user views in django?

Django is making very nice forms after creating a models.py and an admin.py. How can I reuse these forms (with the extra nice handling of foreign keys and many-to-many fields) in my own views? ModelForm does only generate "simple" forms. Where do I get the extra batteries? ...

Django Forms - Can the initial value of one field be dependant on another?

Example, for this form: >>> class CommentForm(forms.Form): ... name = forms.CharField(initial='class') ... action = forms.ChoiceField(...) Can I have the choices in the action field be different depending on what is in the name field? ...

Django form not saving default image name

I've got a form which includes the option to upload an image. In my model, I've defined a default image name to use when no image is selected for upload. When selecting a file, the form uploads the file to my media directory and properly places the filename in the db field (working as it should). When not selecting a file, that field ...

unique_together validation fails if one of the fields is excluded from form

I have a model Menu: class Menu(models.Model): loja = models.ForeignKey(Loja, related_name='menus') nome = models.CharField(max_length=30) ordenacao = models.IntegerField(blank=True, null=True) class Meta: ordering = ('ordenacao',) #prevent equally named menus within a store(loja) unique_together...

How to create a resizeable TinyMCE textarea?

I have a Django form using textareas and TinyMCE for text entry. I would like to add a slider to change the vertical size of the textarea, like SO has them so nicely. How can this be done? ...

Extending forms.SelectMultiple Without Losing Values

I have a model form that I am writing a custom widget for in order to replace the many-to-many forms.SelectMultiple fields with jQuery FCBKcomplete widgets. While the replacement of the multiselect element works fine, it is no longer pulling the options for the multiselect. Here is my widget: class FCBKcompleteWidget(forms.SelectMultip...

Country/State/City dropdown menus inside the Django admin inline

I have a city foreign key in by BusinessBranch model. My City model also has a state and country foreign keys for State and County models. I'm having hard time displaying State and Country dropdown menus inside my BusinessBranchInline. What would be the best way to achieve this? It would be great if the dropdowns filter items based on th...

Django forset populates with different objects when saving.

I display a formset, which has Forms populated by the objects returned by a queryset. The problem is that before the user submits items are modified or added, such that the queryset returns objects in a different order. The formset then associates each form with the wrong object, users report that their data is shifting down by 1 row. Is...

Django Formsets - form.is_valid() is False preventing formset validation

I'm am utilizing a formset to enable users subscribe to multiple feeds. I require a) Users chose a subscription by selecting a boolean field, and are also required to tag the subscription and b) a user must subscribe to an specified number of subscriptions. Currently the below code is capable of a) ensuring the users tags a subscription...

Django Forms not rendering ModelChoiceField's query set

I have the following ModelForm: class AttendanceForm(forms.ModelForm): def __init__(self, *args, **kwargs): operation_id = kwargs['operation_id'] del kwargs['operation_id'] super(AttendanceForm, self).__init__(*args, **kwargs) self.fields['deployment'].query_set = \ Deployment.objects.filt...

Can Django admin handle a one-to-many relationship via related_name?

The Django admin happily supports many-to-one and many-to-many relationships through an HTML <SELECT> form field, allowing selection of one or many options respectively. There's even a nice Javascript filter_horizontal widget to help. I'm trying to do the same from the one-to-many side through related_name. I don't see how it's much dif...

How to set an event handler in a Django form input field

How to set a JavaScript function as handler in the event onclick in a given field of a Django Form. Is this possible? Any clue would be appreciated. ...

How to pass initial parameter to django's ModelForm instance?

The particular case I have is like this: I have a Transaction model, with fields: from, to (both are ForeignKeys to auth.User model) and amount. In my form, I'd like to present the user 2 fields to fill in: amount and from (to will be automaticly set to current user in a view function). Default widget to present a ForeignKey is a selec...