django-forms

Django: iterating over the options in a custom select field

Hi, I'm using a custom MM/YY field and widget based on this example. I want to iterate over the individual month and year options defined in the widget class in order to apply "selected='selected'" to the MM/YY value that corresponds with the MM/YY value stored in the database. This seems like such a messy way of doing this, so if you...

Set attribute of a model to a certain value before saving.

I have this: class OrderForm(ModelForm): class Meta: model = Order exclude = ('number',) def __init__(self, *args, **kwargs): super(OrderForm, self).__init__(*args, **kwargs) if self.initial.get('account', None): self.fields['customer'].queryset = Customer.objects.filter(account=self....

Django form from related model

You have models: class Order(Model): date = DateField(editable = False, auto_now_add=True) status = CharField(max_length = 1, choices = STATUS, default = 'N') profile = ForeignKey(Profile, related_name = 'orders', blank = True, null = True) shipping = ForeignKey(Shipping, related_name = 'orders', blank = True, null = True) address ...

django change form field in .html template output

Hi, I create a form based on a model , like seen below: class ContactSelectionForm(forms.ModelForm): contacts = ManyToManyByLetter(Contact, field_name="first_name") class Meta: model = ContactSelection exclude = ('created_by',) When I process this view I see at the .html output a field labeled with "Contact"...

django many2many field make not required

Hi, I created a form based on a model. The model has a many2many field. I defined the field like this: contacts = models.ManyToManyField(Contact, blank=True, null=True) I`m wondering now why the generated form says that this field cannot be blank. I always get the error message "This field is required.", when i do not select a contac...

django inline editing - inline form only required if at least one field is filled out

Hi, I created a view which returns a form including a contact form and two phone_number forms, following this example: multiple forms The phone number forms should only be validated if the user inserts at least a value for one field in a phone number form. For example: a phone number has a type and a number. If the user is selecting ...

HTML Form Building / Django request.POST help

I'm not sure if I'm just form building impaired or not thinking about this the right way. I'm attempting to build a form similar to Gmail's 'compose' form that has an AJAX image uploader. I have a portion of code that uploads the image and returns an image ID working fine. Once I receive the image ID back I've tried appending it to my...

Passing **kwargs to Django Form

I am trying to build custom django form for changing username and user email for an application. That's why I need to pass the user details from the session to a form in order to check if the logged user exists. I am doing in this way: in views.py personal_info_form = PersonalInfoForm(prefix='personal_info', user_details=user_details) ...

django form dropdown with all users in it

Hi, I want to create a form which has a dropdown with all users in it. I tried it like this, with no luck. class ContactFilterByClassificationForm(forms.Form): kam = forms.ChoiceField(choices=User.objects.all()) ...

Registration form with profile's field

Hi at all, I have a simply question. This is my profile: class Profile(models.Model): user = models.ForeignKey(User, unique=True) born = models.DateTimeField('born to') photo = models.ImageField(upload_to='profile_photo') I want to create a REGISTRATION FORM with this fields ( from User and Profile models ): username, first_name...

Empty Request.FILES with Django Upload forms

Trying to use a very simple form to upload a file into a new class instance. I am expecting to have both files in request.FILES but it's empty. I am on the bundled dev server. been stuck here and went through all related questions ... wayfinder_map.media_file = request.FILES['media_file'] generates MultiValueDictKeyError: "Key 'medi...

POST request returns back to admin index page with "You don't have permissions to edit anything"

I am overriding the admin index.html template by adding at the end: <h1>Exporting and Validating Users</h1> {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} {% if export_message %} <p><strong>{{export_message}}</strong></p> {% endif %} <table> <tr> <td> <form action=...

Accessing request object from form.save

I'm using the pyfacebook module for Django to implement facebook Connect for one of my sites, I'm not using a local User object because I only want to use Facebook for login. I understand that I can't access the request object from the save method on a Django form, so how would I access the facebook object that the provided middleware g...

Jquery in Django: Which django apps should I look into?

I want to use some jquery in my forms and I was hoping to use some ready made solutions - there seem to be a lot of them... Which django apps would you recommend for this purpose? Which are most popular? EDIT #1: Hmmmm... I suppose I didn't put enough effort into my question... I was hoping for more options/clarifications... There se...

Django autocomplete widget example

Hi at all, I am looking for a working simple example on autocomplete widget for foreign key in Django. I have found many example but I don't understand and doesn't work. This is my model: class profile(models.Model): user = models.ForeignKey(User, unique=True) class profileForm(ModelForm): user = forms.CharField(widget=AutoComplete...

Debugging Django Forms validation errors

One of my forms fails on form.is_valid() First time I debug a Django form so I am not too sure where to look forms.py class ImageForm(forms.ModelForm): def __init__(self,user,*args,**kwargs): super(ImageForm,self ).__init__(*args,**kwargs) # populates the form class Meta: model = KMSImageP fields = ('name', ...

Django forms: custom error list format

New to python and django. Using the forms module and going through the errors one by one (so not just dumping them at the top) I noticed this solution to be able to set a custom format for errors, in my case, it'd be: <dd class="error">errstr</dd> And more or less copying the example provided, I have the following: forms.py ( I expan...

Getting a list of errors in a Django form

I'm trying to create a form in Django. That works and all, but I want all the errors to be at the top of the form, not next to each field that has the error. I tried looping over form.errors, but it only showed the name of the field that had an error, not an error message such as "Name is required." This is pretty much what I'd like to ...

Django: Why does my CharField not get given the class vTextField?

I have a form like this: class DiaryEventForm(forms.Form): title = forms.CharField(max_length = 200) Which generates this HTML: <input id="id_title" type="text" name="title" maxlength="200" /> This shows up as really narrow in the admin (where I've got a custom view using this form). If I have a model defined like this: class ...

Model form is crashing on a foreign key in django

So I'm trying to create a new feed within the Admin page and its crashing with the error IntegrityError: lifestream_feed.lifestream_id may not be NULL, form['lifestream'] is set but form.instance.lifestream is not. form.fields even shows that lifestream is a django.forms.models.ModelChoiceField Here is the code: class FeedCreationFo...