django-forms

Redirect to a new form in Django Admin on Save

Hi I am creating a trouble ticket app for my company, and I want to redirect the user to a new form where he will specify the diagnose and solution he offered. my admin is Basically, Right now my code is calling the first form, when the obj created is new or the status is open and it is calling the ClosedForm when my status is closed. ...

Submitting form without redirects in Django

In my main page I have included a template with form for adding emails to newsletter. I'd like this form to add new emails without redirecting anywhere. How I can achieve that ? Here is my code, when I was using separate page for this : views : def newsletter_add(request): if request.POST: f = NewsletterForm(request.POST) ...

Django: Saving an image file from a form

I want to save the image which as been uploaded via the PaletteGenForm as such: #Form class PaletteGenForm(forms.Form): im = forms.ImageField(required=True) #View def palette_gen_view(request): PATH_OF_IMAGE_TO_BE_PALETTED= MEDIA_ROOT+ "/tobesaved.png" if request.method == 'POST': form = PaletteGenForm(request.POST...

Django: How to access modelform field data in templates

I have a page which displays a form that a logged-in user can use to edit their profile. The first time the user loads the corresponding view, with a GET request, the form should display the values of the users existing profile record. Because I'd like to have granular control over the markup used for the form fields, I'd like to retri...

Django: How do I use a different form_class with django-registration

I want django-registration (version 0.8) to use my custom form rather than the default one. However, I want to continue to use the default django-registration view. What should the rest of the line below look like to achieve this? (r'^accounts/register'...), I've tried this below but get a syntax error: (r'^accounts/register/$', ...

How do I change the value of submitted form data using form object and redisplay it?

Essentially I want to sanitize some data a user submits in a form when I redisplay it if there is an error. This is easy to do if I am extracting the data from a form object. I can override the clean() method and manipulate the data. I can also set the .initial value for the first time it is displayed. However, I cannot find a way of...

Django form items disappear

Form items disappear (forms.ModelMultipleChoiceField) if forms.CharField is not part of the form. forms.py class Test(ModelForm): name = fields.CharField(max_length=200) events = forms.ModelMultipleChoiceField(queryset=Event.objects.all()... class Meta: model = Events fields = ("events", "name") The abo...

empty_form initial value for a modelformset_factory

I try to add initial values to the empty form of a modelformset_factory. FormSet = modelformset_factory(MyModel, extra=2) formset = FormSet(queryset=MyModel.objects.none(), initial=[{'foo': 'bar'}, {'foo': 'bar'}]) I would like to set initial value to the formset.empty_form , how can I achieve this ? ...

Django: How to check if there are field errors from within custom widget definition?

I'd like to create widgets that add specific classes to element markup when the associated field has errors. I'm having a hard time finding information on how to check whether a field has errors associated with it, from within widget definition code. At the moment I have the following stub widget code (the final widget will use more co...

form.cleaned_data as a dictionary

Why when I call a function like this : function(request, **form.cleaned_data) I can send form's data as a dictionary, but when I try doing like this : data = **form.cleaned_data I'm getting error ? ...

Django: Attaching additional information to form fields

Hi, I'm trying to pass on additional information to fields of a Django form to be displayed in a template. I tried to override the constructor and add another property to the field like this self.fields['field_name'].foo = 'bar' but in the template this {{ form.field_name.foo }} didn't print anything. Does anyone know how to add a...

Management form error while using modelformsets ('ManagementForm data is missing or has been tampered with')

I have a models.py class as below class Educational_Qualification(models.Model): user = models.ForeignKey(User) exam = models.CharField(max_length=40) pass_month = models.CharField(max_length=40) I have a views.py as below def create_qualification(request): QFormSet = modelformset_factory(Educational_Qualification, extra=3,...

Django FileField: how to set default value (auto-create empty file)?

I've got a model like this: class MyModel(models.Model): name = models.CharField(max_length=255) code = models.FileField() When a new MyModel is submitted, I want to allow for the code field to be left empty, in which case I need Django to create an empty file (with arbitrary name). Question is: what is the right way to do it...

recaptcha refresh button in django

I am using recaptcha django form following this tutorial . It works fine only the little refresh button not working on the recaptcha image. Not sure what is going on. the generated code of recaptcha <script>var RecaptchaOptions = {theme : 'white'};</script><script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6Lc6YL...

(Django) saving string to EmailField raises 'invalid literal for int() with base 10'

In my user's data edit form I have a boolean field, for adding/removing email from newsletter. I've written a custom save method for this form : def save(self, *args, **kwargs): mail = None if self.cleaned_data['inf_newsletter']: mail = NewsletterEmails(self.instance.user.email) mail.save() else: ...

Display a series of dropdown lists with past dates in Django.

I am using model forms in Django to allow the user to enter in their birthdate. I want to have the user select the date from a series of dropdown lists, one each for year, month, and day. Originally I thought that the SelectDateWidget would work. However that particular widget only displays dates in the future. I of course want to only d...

Django/jQuery Cascading Select Boxes?

I want to build a Country/State selector. First you choose a country, and the States for that country are displayed in the 2nd select box. Doing that in PHP and jQuery is fairly easy, but I find Django forms to be a bit restrictive in that sense. I could set the State field to be empty on page load, and then populate it with some jQuery...

Strange validation error messages

I'm using the standard authentication form. It's clean method looks like this : def clean(self): username = self.cleaned_data.get('username') password = self.cleaned_data.get('password') if username and password: self.user_cache = authenticate(username=username, password=password) if self.user_cache is None:...

Django (1.2) Forms: ManyToManyField Help Text

I hope I'm wrong, but it looks to me like the only way to have no help_text for a ManyToManyField is write an __init__ method for the form and overwrite self.fields[fieldname].help_text. Is that really the only way? I prefer to use CheckboxSelectMultple widgets, so am I really going to have to define an __init__ method for any form that ...

django forms - edit object after form submitted the first time

I am using django forms to add a new objects to the db. The code I currently have is: if request.method == 'POST': form = MyForm(data=request.POST) if form.is_valid(): obj = form.save() else: form = MyForm() return render_to_response('reflections/add_reflection.html', {'form':form},context_instance=RequestContext...