django-forms

How do you use the django 1.2 form validators?

I have been trying to use the new validators that are now included with Django. I have set the validators parameter on my fields and while I don't get an error, the validation doesn't seem to be working. Here is my console session that dupplicates the issue. Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on...

What's the best way to handle different forms from a single page in Django?

Let's say I have the 3 different forms defined in my view: # views.py form_one = FormOne() form_two = FormTwo() form_three = FormThree() In my template: <form action="" method="post" id="form-one"> {{ form_one.as_table }} <input type="submit" value="Submit Form One" name="form-one" /> </form> <form action="" method="post" id="fo...

Django can't find my non-python files!

I can't, for the life of me, get Django to find my JavaScript files! I am trying to plug in a custom widget to the admin page, like so: class MarkItUpWidget(forms.Textarea): class Media: js = ( 'js/jquery.js', 'js/markitup/jquery.markitup.js', 'js/markitup/sets/markdown/set.js', 'js/markitup.init.js',...

Django forms breaking in IE7

I've got a dango webform from a model with some error checking (valid email field,etc). Everything works fine in variopus browsers Opera,Camino,Netscape,Safari and IE (except IE7). All I get in IE7 is the 'Internet Explorer cannot display the webpage' message. If the forms valid the data gets written to the database so I think its somet...

How to avoid NotImplementedError "Only tempfile.TemporaryFile is available for use" in django on Google App Engine?

I'm using django 1.1 on Google App Engine through use_library. No django gae helper, django-nonrel or similar tools are used here. Django handles urls routing, forms validation etc., but I'm using pure appengine models. In one of my django's forms there is a FileField, which from time to time seems to call django.core.files.uploadedfile...

Django: How to define a dynamic initial value on a ForeignKey Model Field

How can one define a dynamic initial value on a foreign key field? With the code: from django.db import models from django.conf import settings from django.contrib.sites.models import Site class Example(models.Model): site = models.ForeignKey(Site, initial=settings.SITE_ID) I've the following error: site = models.ForeignKey(Sit...

Django Form with no required fields

Hi, I want to make a form used to filter searches without any field being required. For example given this code: models.py: class Message(models.Model): happened = models.DateTimeField() filename = models.CharField(max_length=512, blank=True, null=True) message = models.TextField(blank=True, null=True) dest = mod...

Why are my forms not returning field errors?

Recently I upgraded my django server. Going from 1.2 to a new version. The forms exhibit a strange behavior. When a field is left blank the whole page simply refreshes, rather than showing errors like I remember. What could cause this? What ought I do to fix it? {%extends "baseAUTH.html" %} {% block title %} {{ title }} ...

Django dynamic form ValidationErorr

I'm trying to modify the admin ModelMultipleChoiceField so it does load data dynamically. Because I want to load data dynamically the queryset for ModelMultipleChoiceField is empty when creating an instance of the form, for that reason when doing form validation django complains that the choices aren't valid because they can't be foun...

Django multiple form factory

What is the best way to deal with multiple forms? I want to combine several forms into one. For example, I want to combine ImangeFormSet and EntryForm into one form: class ImageForm(forms.Form): image = forms.ImageField() ImageFormSet = formset_factory(ImageForm) class EntryForm(forms.Form): title = forms.CharField(max_length=1...

How to change multiple select field to multiple input fields for a many-to-many case?

When I display the ToolBoxEditForm it uses a multiple select field. But what I want is a form that lets the user edit each tool he has in the toolbox as a text field. I cant figure out how to do this with the many-to-many field. class Tool(models.Model): tool_name = models.CharField(unique=True, max_length=200) ...... class ToolBox...

Django model field with default value set violates not null constraint when saved.

My field: signup_date = models.DateTimeField(blank=True,default=datetime.now) My error when saving: IntegrityError: null value in column "signup_date" violates not-null constraint I'm trying to make a simple unit test where I create a bound instance of a ModelForm from a dict and save it. Thanks. Traceback (most recent call last)...

How do I post to a Django 1.2 form using urllib?

Going off of this other SO question, I tried to use urlencode and urlopen to POST data to a form. However, Django 1.2 gives me a CSRF verification failed error when I use it. Is there a workaround? Thanks. ...

Django FloatField in ModelForm with 2 precision point

Hello All, I have a FloatField in one of my model. I Add/Edit it using ModelForms. What I need is that, when i edit, the Float value stored in FloatField to be rendered with exactly 2 precision points. i.e. if my stored value is 1000.0 or 1000.123, i want the input field of form to show initial value of 1000.00 or 1000.12. Any suggest...

django forms ModelChoiceField

HI! I want to be able to select from something like this: Let's say the number and student name, both in the same line and both will appear. 1 John 2 Marie 3 Jane (..) So what I've done in the forms is: class StudentForm(forms.Form): std = tuple of number and name nbr = forms.ModelChoiceField(student, choices=std, widget=Sele...

How to display many-to-many field as a list of text input fields?

When I display the ToolBoxEditForm it uses a multiple select field. But what I want is a form that lets the user edit each tool he has in the toolbox as a text field. I cant figure out how to do this with the many-to-many field. class Tool(models.Model): tool_name = models.CharField(unique=True, max_length=200) ...... class ToolBox...

Localization don't work on a ModelForm in Django

Hi, I have this model def Person(models.Model) name = models.CharField(max_length=50) birth_date = models.DateField() and I have this form def PersonForm(forms.ModelForm) class Meta: model = Person I'm localize the project to spanish (es), and add a customized format module (FORMAT_MODULE_PATH) to set DATE_FORMAT = ...

Fields of Django FormWizard are shared between users?

Hello guys, Some time ago I found at SOV how to dynamically add fields to a FormWizard form. ( http://stackoverflow.com/questions/1256194/django-wizardform-and-second-form-will-be-dynamic) I did as described and everything worked flawlessly. Until 2 users start doing the same FormWizard at the same time. Then they start seeing each oth...

Editing related models in profile form using django-profiles

I'm using django-profiles in my app, as it gives me a few simple views that helps me get where I want to go, faster. However, I have one problem. Given the models below, how can I create a form for editing a profile that includes all the fields on UserProfile, the first_name, last_name and email fields from User, and one or more PhoneNu...

How to make required field error message don't show up for first time in Django

First time I render a form I don't want the required error message to show up. Although if the field is left empty, it should prompt when submitting. I know I can set an specific message and set it empty. But this way it never shows up: error_messages = {'required':''} I'm using a decorator to change label_tag behavior in BoundField,...