django-forms

Is it possible to add a single row to a Django form?

I have a form along the lines of: class aForm(forms.Form): input1 = forms.CharField() input2 = forms.CharField() input3 = forms.CharField() What I'm hoping to do is add an additional input3 to the form when the user clicks an "add another input3". I've read a bunch of ways that let me add new forms using formsets, but I don't w...

Django: Custom widget that can pre-fill from POST/GET data

Updated with my final solution, below. I wrote a custom Django form widget to create a range query. It renders two input fields to define the min and max values for a query. With well-crafted forms and widgets, fields can be filled with the values from the last query like so: form = my_form(request.GET) However, I cannot figure ou...

Render Radio Button Django

I Have this Form class MyModelForm(forms.ModelForm): boolfield = forms.TypedChoiceField(coerce=bool, choices=((False, 'No'), (True, 'Yes')), widget=forms.RadioSelect ) class Meta: model = MyModel How can I show the buttons without LI an UL tags ? (I want to show them together horizontall...

Django form does not display when only one field is being used

I have a django model and model form that look like this: -models.py class Menu_Category(models.Model): merchant = models.ForeignKey(Merchant, related_name='menu_categories') name = models.CharField(max_length=64) test_field = models.CharField(max_length=20) def __unicode__(self): return self.name -forms.py cla...

Django -- Password Clean fails when min_length is set.

I have a user registration form that has a "password" and "confirm password" field. When I add "min_length" to my password field and then run the submitted data through my custom clean_confirm_password method, it gives a "Key Error / Password" error. This occurs when the password field is less than 5 characters, whether the confirm_pass...

Django: How to limit size of uploaded image when using a ModelForm ?

I have in my model an ImageField, and I am using forms.ModelForm to edit the form. I didn't find a way to make the ModelForm limit the uploaded image file size ...

Django - How can I access model field validators from within form template?

Hi, In my generic form template, if a CharField has a max_length attribute, I display that beside the field. Form template: {% if field.field.max_length %} Max. {{ field.field.max_length }} char. {% endif %} I want to do this for TextFields, where max_length is not used, defined like that in the model: class Entry(models.Model)...

django Custom ManyToMany save on model Formset Options

Hello everyone, I have a formset that is setup to use a join table. The join table joins a Recipe table and an Ingredient table and looks like thus class RecipeIngredient(models.Model): '''intermediate model between Ingredient and recipe.models.recipe for many to many''' quantity = models.IntegerField() measurement ...

Remove items with checkboxes in Django forms

I'm writing a form with Django. The form is a model form for a certain model, Experiment. Each Experiment has several TimeSlot models associated with it, defined with a ForeignKey('Experiment'). I'd like to have a form with the option to remove one or more TimeSlot instances from the EditExperimentForm by checking boxes. Currently, I d...

Django forms: Changing help_text dynamically

Is this even possible? So let's say that I have two forms, one inherits from the other because they have similar fields with the same validation. But the only difference is they have different help text. How could I have two different help text on these forms? ...

django forms into database

hey guys, im trying to make a volunteer form, that takes info such as name, last name, etc. and i want to save that info into my database (MySQL), so that it can be retrieved later on . ...

Django: how to validate the complete form

Hi I have a form which has two fields for Integers: class DemoForm(forms.Form): b_one = forms.IntegerField( error_messages={ 'required':'Please enter a valid number.' }, label = 'NumberOne', required = True, help_text = 'e.g. 266492' ) b_two = forms.IntegerField( error_messages={ 'required':'Please...

How to show search results no same

Hi I am new to Django, and want to do the following I have a form that takes two inputs, processes and forwards the results to another page. I want to display the results in the same page with form page included. How can I do that in Django? Thank you ...

How to display choices in my form using django forms?

Hi, I have a model that looks like this in my application: class Member(models.Model): name = models.CharField(max_length=200) telephone_number = models.CharField(max_length=200) email_address = models.CharField(max_length=200) membership_type = models.CharField(max_length=1, choices=MEMBERSHIP_TYPES) membership_num...

Adding an error to a django form in a view... hack?

What I'm trying to do is to add an error for a field in a view, AFTER both form.is_valid() and form.save(), and it seems to work but only because of a hack, and I'm hoping someone here can explain why it works. So in my form's save() function, I connect to an LDAP server, and try to authenticate the user and password supplied in the for...

Customizing UserCreationForm for email address as username in Django 1.2

Django 1.2 adds new allowable symbols to usernames, meaning usernames can simply be email addresses. Up until now I have been using the inbuilt UserCreationForm for registration - how can I alter it to label the 'username' field the 'email' field? And how also to add extra (but still User object) fields such as first and last names? (And...

Creating a user profile form in Django 1.2

Hi, I'm trying create a basic form which will allow the user to update their firstname, lastname and email as part of the User model. I've tried the following code: from django.forms import ModelForm from django.contrib.auth.models import User class BasicAccountForm(ModelForm): class Meta: model = User fields = ('f...

Change django form value

I have changed a ForeignKey in a model form, to use a TextBox instead. Then I override clean method to return the object based on the name field (instead id field) class SongForm(forms.ModelForm): artist = forms.CharField(widget=forms.TextInput()) def clean_artist(self): data = self.cleaned_data['artist'] artist = Artist.ob...

modelform fails is_valid w/o setting form.errors

I'm using a modelform to display only a subset of the fields in the model. When the form is submitted it fails form.is_valid() but form.errors is empty. I'd rather not display all my code here, but below is a sample: Model and Form class Videofiles(models.Model): active = models.CharField(max_length=9) filenamebase = models.Cha...

Formset Creating New Entries Instead of Updating

I have the following code in a view: def controller_details(request, object_id): controller = Controller.objects.get(pk=object_id) controllerURI = controller.protocol + '://' + controller.server + '/' + controller.name FilterFormSet = inlineformset_factory(Controller, Filter, extra=2) if request.method == 'POST': ...