django-forms

Easy way to submit POST data from a hyperlink in Django? Equivalent of Rails' `button_to`?

Is there a quick way to submit (pre-defined) POST data from a hyperlink in a Django template? I've got an 'add this to my favourites' link on page. I'm currently doing this with a GET request, which obviously breaks all kinds of rules. I could manually build a form and have the link submit it with Javascript. I'm looking for an automat...

How to sort order in Django Related Models (Generic relations)

My models: HitCounter: hits = models.PositiveIntegerField(default=0) object_pk = models.TextField('object ID') content_type = models.ForeignKey(ContentType, verbose_name="content cype", related_name="content_type_set_for_%(class)s",) content_object = generic.GenericForeignKey('conte...

Clearing Django form fields on form validation error?

I have a Django form that allows a user to change their password. I find it confusing on form error for the fields to have the *'ed out data still in them. I've tried several methods for removing form.data, but I keep getting a This QueryDict instance is immutable exception message. Is there a proper way to clear individual form fields...

Dynamically Delete inline formsets in Django

Is it possible to have Django automatically delete formsets that are not present in the request? So for example if I had three inline formsets represented in HTML when I loaded my edit page and I use javascript to remove two of those when the request is processes Django sees that those two forms are no longer their and deletes them. ...

problem with select and related model

I have models like this: class IdfPracownicy(models.Model): nazwa = models.CharField(max_length=100) class IdfPracaOpinie(models.Model): nazwa = models.CharField(max_length=30) class IdfPraca(models.Model): numer_idf = models.ForeignKey(IdfPracownicy) [...] opinia = models.ForeignKey(IdfPracaOpinie) uwagi = model...

How to get a list of queryset and make custom filter in Django

I have some codes like this: cats = Category.objects.filter(is_featured=True) for cat in cats: entries = Entry.objects.filter(score>=10, category=cat).order_by("-pub_date")[:10] But, the results just show the last item of cats and also have problems with where ">=" in filter. Help me solve these problems. Thanks so much! ...

Overwrite clean method in Django Custom Forms

Hi I have wrote a custom widget class AutoCompleteWidget(widgets.TextInput): """ widget to show an autocomplete box which returns a list on nodes available to be tagged """ def render(self, name, value, attrs=None): final_attrs = self.build_attrs(attrs, name=name) if not self.attrs.has_key('id'): final_attrs['id'] = 'id...

Django Form inheritance problem

Why can't I do this? from django import forms from django.forms import widgets class UserProfileConfig(forms.Form): def __init__(self,*args,**kwargs): super (UserProfileConfig,self).__init__(*args,**kwargs) self.tester = 'asdf' username = forms.CharField(label='Username',max_length=100,initial=self.tester) Mo...

Django - Access request.session in form

I am calling a form as follows, then passing it to a template: f = UserProfileConfig(request) I need to be able to access the request.session within the form... so first I tried this: class UserProfileConfig(forms.Form): def __init__(self,request,*args,**kwargs): super (UserProfileConfig,self).__init__(*args,**kwargs) ...

Django - Working with multiple forms

Hi everybody! What I'm trying to do is to manage several forms in one page, I know there are formsets, and I know how the form management works, but I got some problems with the idea I have in mind. Just to help you to imagine what my problem is I'm going to use the django example models: from django.db import models class Poll(model...

Django Newbie here... Is there a good way of handling empty MultipleChoiceField results (like a List-Comp format?)

Hello there, I came across this blog entry which describes an elegant way of handling results returned from a ChoiceField to a view using a list comprehension technique - one that eliminates empty keys/values without all the intermediate data structures. This particular approach doesn't seem to work for MultipeChoiceFields, though. Is t...

Django: FormWizard runs but one instance when it's URL is requested multiple times

Hi all, I found out that the FormWizard only __init__'s once, when the url is request by multiple users at the same time (me in 2 browsers :). This results in the fact that my temporarily stored data on the wizard's instance is wrongfully shared between users. I'm doing some DB hits in the second step, and based on that outcome I do a...

Busy server indication during django forms POST

How can I show a busy server icon to a user for Django form post and remove it with failure or success message when a response from the background process is receive ? I cannot do the POST using javascript. Thanks ...

Creating a custom Django form field that uses two <input>s.

How can I make a Django field that renders itself as a pair of input fields? Reasoning: I am trying to write a new custom field. I will use it for a captcha-like service. The service works by requesting a question - then receiving one and a token. The validation happens by sending the answer along with the token. I want to write a form ...

How to edit/add objects using the same django form?

Hey, I've searched around to do this (particularly this Q: http://stackoverflow.com/questions/1854237/django-edit-form-based-on-add-form) but I just can't get it to work. The problem I'm having is that the form always creates a new object, instead of modifying the existing one. This is my code: def new_task(request, task_id=None): if...

Using valid HTML 4.01 Strict with Django

I've found a similar question here, but I'm looking for more general solutions. As it is now, when Django generates anykind of HTML for you (this mainly happens when generating forms), it uses self-closing tags by default i.e. <br /> instead of <br>. <br /> is valid XHTML and I think HTML5 also, but it's not valid HTML4. Is there any c...

Django Admin: Detect if a subset of an object fields has changed and which of them

I need to detect when some of the fields of certain model have changed in the admin, to later send notifications depending on which fields changed and previous/current values of those fields. I tried using a ModelForm and overriding the save() method, but the form's self.cleaned_data and seld.instance already have the new values of the ...

Django FormWizard and ImageFields

I need to create a Django FormWizard asking for the user personal data in the first step and for an image in the next step(there are more steps asking for personal data later). I can store all the data in the database except the ImageFields I read this http://code.djangoproject.com/ticket/7439 , I apply the suggested patch to my django...

Django, form valid question

Hello I have 3 forms at the same page and each has a different form submit. Such as: <h1>Address</h1> <form method="post" id="adress_form" action=/profile/update/> {{ form_address.as_p }} <p><button type="submit">Save</button></p> </form> <h1>Email Change</h1> <form method="post" id="email_form" action=/profile/update/> {{ form_email...

django request.POST

Hi I have an array of checkboxes e.g. <input type="checkbox" name="checks[]" value="1" /> <input type="checkbox" name="checks[]" value="2" /> <input type="checkbox" name="checks[]" value="3" /> <input type="checkbox" name="checks[]" value="4" /> How do I access these in the view.py if more than one is selected? I have tried request...