django-forms

Django multi-select widget?

The Django admin site makes use of a really cool widget: How can I make use of this widget in my own applications? I don't see anything like that listed here. ...

django, uni_form and python's __init__() function - how to pass arguments to a form?

I'm having a bit of difficulty understanding how the python __init__( ) function works. What I'm trying to do is create a new form in django, and use the uni_form helper to display the form in a custom manner using fieldsets, however I'm passing an argument to the form that should slightly change the layout of the form and I can't figure...

Editing both sides of M2M in Admin Page

Hello all, First I'll lay out what I'm trying to achieve in case there's a different way to go about it! I want to be able to edit both sides of an M2M relationship (preferably on the admin page although if needs be it could be on a normal page) using any of the multi select interfaces. The problem obviously comes with the reverse sid...

Python/Django Model overriding the cleaned data

Hello I am currently working on a django project, in one of my Models I have a file upload and image upload, with the parameters of these two fields both are set to blank=True, however there is a stipulatation with this and it is that field can only be blank if one of the two is not, so for example, if the imagefield is complete then the...

Alternate forms libraries on django eg sprox, formalchemy

Has anyone had any joy/pain with using other form libraries in django projects (with SQLAlchemy models initially, but perhaps to use with django models in future)? Initial impressions are that sprox is more flexible and decoupled but that formalchemy might be quicker to get up and running with, but I'd be really interested in hearing fr...

Customize HTML Output of Django ModelForm

I am trying to add multiple inline form items to a page using Djangos ModelForms. I need Select boxes bound to database models. The forms are formatted and placed in a tabular format so I need to display only the ModelForm without ANY surrounding HTML. class LeagueForm(ModelForm): league = forms.ModelChoiceField(queryset=League.objects....

Custom save method giving invalid tuple size error

I've been stuck on this likely very simple problem, but haven't gotten anywhere with it (newbie to Python and Django). I'm taking some user submitted data and using weights to calculate a score. Despite my best efforts, I'm getting the following when I submit the data via a form: "global name 'appearance' is not defined". I'm pretty s...

Django select record based on search results

I am a complete beginner trying to build an inventory app in Django by copying examples. There are two models of interest, a item record and a name record. The item has a primary key - the manufacturer's serial number (an 11 character mix of letters and numbers) and an inventory tag (charField of 20 chars or less - which could be blank)....

How to create a UserProfile form in Django with first_name, last_name modifications ?

If think my question is pretty obvious and almost every developer working with UserProfile should be able to answer it. However, I could not find any help on the django documentation or in the Django Book. When you want to do a UserProfile form in with Django Forms, you'd like to modify the profile fields as well as some User field. B...

what is attr 'gtbfieldid' and how to avoid autocomplete behavior ?

Hi, I have this simple form: class PagoDesde(forms.Form): from django import forms as f desde = f.DateField(input_formats=['%d/%m/%Y']) In my template: {{ form.desde }} And has associated a jqueryui.datepicker in the document.ready $("#id_desde").datepicker(); The html result is: <input type="text" id="id_desde"...

Django: provide choices list to a checkbox from a view function

Hi, in my Django application I've got a form with a ChoiceField that normally allows to choice between a range of integer values. class FormNumber(forms.Form): list=[] for i in range(1, 11): list.append((i,i)) number=forms.ChoiceField(choices=list, initial=1) Now I need to override the default choices list from a view method in some ...

Customize the html output of Django's form validation

Whenever you use a {{ form.field.errors }} tag in a Django template, the validation message that is displayed is always surrounded with a unordered list tag. This is not ideal for me. Am I able to modify the surrounding validation message html for a form from a reusable package? ...

ChoiceField doesn't display an empty label when using a tuple - am I doing something wrong?

What I'm trying to do I'm going to be keeping data about competitions in my database. I want to be able to search the competitions by certain criteria - competition type in particular. About competition types Competition types are kept in a tuple. A slightly shortened example: COMPETITION_TYPE_CHOICES = ( (1, 'Olympic Games'), ...

how to insert a infomation on a table in Django

This is my form on models.py class ItemForm(forms.Form): itemname = forms.CharField(max_length=100) itemwording = forms.CharField(max_length=100) notes = forms.CharField() abundance = forms.IntegerField(max_value=10) collunit = forms.CharField(max_length=50) litref = forms.CharField(max_length=100) litkey = ...

Django MultiWidget Phone Number Field

I want to create a field for phone number input that has 2 text fields (size 3, 3, and 4 respectively) with the common "(" ")" "-" delimiters. Below is my code for the field and the widget, I'm getting the following error when trying to iterate the fields in my form during initial rendering (it happens when the for loop gets to my phone...

Complex forms in Django - what apps and Django/Python features should I look at?

There are a lot of complex forms in my project and I keep getting the feeling that I could be coding them much more elegantly and simply. So my question is what are some good apps and practices that might help me? Specifically, I'm thinking about situations when I need to do stuff like: edit/add more than one object via one form (examp...

Django is_valid() not working with modelformset_factory

I've created a simple contact form using the modelformset_factory to build the form in the view using the DB model. The issue that I am having is that the is_valid() check before the save() is not working. When I submit the form with empty fields it still passes the is_valid() and attempts to write to the DB. I would like the is_vali...

Get type of Django form widget from within template

I'm iterating through the fields of a form and for certain fields I want a slightly different layout, requiring altered HTML. To do this accurately, I just need to know the widget type. It's class name or something similar. In standard python, this is easy! field.field.widget.__class__.__name__ Unfortunately, you're not allowed access ...

Only validate certain fields if a BooleanField is set

Scenario: I'm building an order-form. Like every other order-form on the planet, it has separate invoicing shipping addresses. I've just added a "Use billing address" checkbox to let the user save time. The problem is, the shipping fields are still there. They will fail validation if the user don't enter any shipping address data (like ...

Django modelform: exclude fields by regex

I have a "Villa" Model with lots of descriptive TextFields. For each TextField, I have a copy which will be the Russian translation of the original field, which I'm naming by appending "_ru", for example "long_description" and "long_description_ru". I would like to exclude all the "_ru" fields from my ModelForm, which I thought I would b...