I am trying to automate the creation of something like this:
<input type='text' name='asdf[]' />
<input type='text' name='asdf[]' />
<input type='text' name='asdf[]' />
By cycling through a range in the form. I've been trying things like this, along with several other variations:
# in a model class
for i in range(1, prim+1):
self...
Hi,
I have wrote a custom MultipleChoiceField. I have everything working ok but when I submit the form the selected values go back to the original choices even though the form validates ok.
my code looks something like this:
class ProgrammeField(forms.MultipleChoiceField):
widget = widgets.SelectMultiple
class ProgrammeForm(forms...
Hi,
how do I set the value of a field element after a form has been submitted but has failed validation? e.g.
if form.is_valid():
form.save()
else:
form.data['my_field'] = 'some different data'
I don't really want to put it in the view though and would rather have it as part of the form class.
Thanks
...
Hi,
When overwriting a form clean method how do you know if its failed validation on any of the fields? e.g. in the form below if I overwrite the clean method how do I know if the form has failed validation on any of the fields?
class PersonForm(forms.Form):
title = Forms.CharField(max_length=100)
first_name = Forms.CharField(...
Hi
I have a form field which requires a json object as its value when it is rendered.
When the form is submitted it returns a comma seperated string of ids as its value (not a json string). however if the form does not validate i want to turn this string of ids back into a json string so it will display properly (is uses jquery to rende...
I have a form that looks like this:
class SampleForm(forms.Form):
text = forms.CharField(max_length=100)
In my django template, I want to reference the fact that the length is 100.
I tried
{{ form.text.max_length }}
to no avail.
On a related note, how do I reference this value in python?
...
I'm creating a formset, but it seems to populate it with all of the existing data in the table for that object. I can't figure out how to start with a blank formset; the only way seems to be to delete all of the data from the table, but clearly this isn't an option.
I will post code if necessary (but there's lots of it, so knowing what ...
I a working with Django forms. The issue I have is that Foreign Key fields and those using initial take all associated entries (all records associated with that record other then the one entry i wanted e.g instead of getting a primary key, i get the primary key, post subject, post body and all other values attributed with that record). T...
This post relates to this:
http://stackoverflow.com/questions/520421/add-row-to-inlines-dynamically-in-django-admin
Is there a way to achive adding inline formsets WITHOUT using javascript? Obviously, there would be a page-refresh involved.
So, if the form had a button called 'add'...
I figured I could do it like this:
if request.met...
I have an object Task and a form that saves it. I want to automatically asign created_by field to the currently logged in user. So, my view is this:
def new_task(request, task_id=None):
message = None
if task_id is not None:
task = Task.objects.get(pk=task_id)
message = 'TaskOK'
submit = 'Update'
el...
I'm trying to send email with some images attached in django. Code used is this snippet : http://www.djangosnippets.org/snippets/1063/. Dunno why the attachment part returns me a core error.
THe code. forms.py
from django import forms
from common import slugify_unique
from django.conf import settings
from django.core.cache import cache...
Hello
At my template, I want to iterate through all form errors, including the ones that are NOT belonging to a specific field. ( which means for form.errors, it should also display for __all__ errors aswell)
I have tried several versions, Ie:
<div id="msg">
{% if form.errors %}
<div class="error">
<p><span>ERROR</span></p>
...
I have a form like:
#forms.py
from django import forms
class MyForm(forms.Form):
title = forms.CharField()
file = forms.FileField()
#tests.py
from django.test import TestCase
from forms import MyForm
class FormTestCase(TestCase)
def test_form(self):
upload_file = open('path/to/file', 'r')
post_dict = {'ti...
The code displayed below is providing the choices I need for the app field, and the choices I need for the attr field when using Admin.
I am having a problem with the attr field on the inline form for already saved records. The attr selected for these saved does show in small print above the field, but not within the field itself. ...
I am having problems with django forms and image uploads. I have googled, read the documentations and even questions ere, but cant figure out the issue. Here are my files
my models
class UserProfile(User):
"""user with app settings. """
DESIGNATION_CHOICES=(
('ADM', 'Administrator'),
('OFF', 'Club Official'),
('MEM'...
Django's form library has a feature of form sets that allow you to process dynamically added forms. For example you would use form sets if your application has a list of bookmarks you could use form sets to process multiple forms that each represent a bookmark.
What about if you want to dynamically add a field to a form? An example wo...
Hi,
I have 2 forms in my Django view. How can I do a check to see which one has been submitted?
Thanks
...
I'm fairly new to both Django and Python. This is my first time using forms and upload files with django. I can get the uploads and saves to the database to work fine but it fails to valid email or check if the users selected a file to upload. I've spent a lot of time reading documentation trying to figure this out. Thanks!
views.py
de...
I have a model with a bunch of different fields like first_name, last_name, etc. I also have fields first_name_ud, last_name_ud, etc. that correspond to the last updated date for the related fields (i.e. when first_name is modified, then first_name_ud is set to the current date).
Is there a way to make this happen automatically or do I...
Hi!
I'am developing application on app-engine-path.
I would like to make form with multichoice (acceptably languages for user).
Code look like this:
Language settings:
settings.LANGUAGES = ((u"cs", u"Čeština"), (u"en", u"English"))
Form model:
class UserForm(forms.ModelForm):
first_name = forms.CharField(max_length=100)
...