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.
...
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)
...
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...
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...
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/$',
...
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...
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...
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 ?
...
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...
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 ?
...
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...
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,...
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...
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...
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:
...
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...
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...
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:...
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 ...
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...