django-forms

How to get a single widget to set 2 fields in Django?

Hi, I got a model with 2 fields: latitude and longitude. Right now they're 2 CharFields, but I want to make a custom widget to set it in admin - was thinking about displaying Google Maps, then getting the coordinates of the marker. But can I have 1 widget (a single map) to set 2 different fields? ...

Adding links to full change forms for inline items in django admin?

I have a standard admin change form for an object, with the usual StackedInline forms for a ForeignKey relationship. I would like to be able to link each inline item to its corresponding full-sized change form, as the inline item has inlined items of its own, and I can't nest them. I've tried everything from custom widgets to custom te...

Django: How to get current user in admin forms

In Django's ModelAdmin I need to display forms customized according to the permissions an user has. Is there a way of getting the current user object into the form class, so that i can customize the form in its __init__ method? I think saving the current request in a thread local would be a possibility but this would be my last resort th...

Best way to change Satchmo checkout page fields?

For a Satchmo project we have to change the fields a customer has to fill out during checkout. Specifically, we have to: Add a 'middle name' field Replace the bill and delivery addressee with separate first, middle and last name fields Replace the two address lines with street, number and number extension These fields are expected by...

Is it possible to use template tags in ValidationError's strings?

I need to throw ValidationError containing anchor. if not profile.activated(): raise ValidationError('Your profile is not activated. <a href="{% url resend_activation_key %}">Resend activation key</a>.') What I need to modify to make this work? ...

Django - Form validation error

Hello, I have a model like this: class Entity(models.Model): entity_name = models.CharField(max_length=100) entity_id = models.CharField(max_length=30, primary_key=True) entity_parent = models.CharField(max_length=100, null=True) photo_id = models.CharField(max_length=100, null=True) username = models.CharField(m...

django form and title property

Hi guys, i need to render my forms with the property "title" for jquery validation, how ill render my forms in this way? <input name="name" id="name" title="Please fill Your name!" value="" type="text" /> Thanks guys ...

Display/Edit fields across tables in a Django Form

I have 2 tables/models, which for all practical purposes are the same as the standard Author/Book example, but with the additional restriction that in my application each Author can only write 0 or 1 books. (eg, the ForeignKey field in the Book model is or can be a OneToOneField, and there may be authors who have no corresponding book in...

How can I order fields in Django ModelForm?

I have an 'order' Model: class Order(models.Model): date_time=models.DateTimeField() # other stuff And I'm using Django ModelForm class to render a form, but I want to display date and time widgets separately. I've came up with this: class Form(forms.ModelForm): class Meta: model = Order exclude = ('date_time',) date = forms...

Django: How do I add arbitrary html attributes to input fields on a form?

I have an input field that is rendered with a template like so: <div class="field"> {{ form.city }} </div> Which is rendered as: <div class="field"> <input id="id_city" type="text" name="city" maxlength="100" /> </div> Now suppose I want to add an autocomplete="off" attribute to the input element that is rendered, how would ...

why are read only form fields in django a bad idea?

I've been looking for a way to create a read-only form field and every article I've found on the subject comes with a statement that "this is a bad idea". Now for an individual form, I can understand that there are other ways to solve the problem, but using a read only form field in a modelformset seems like a completely natural idea. ...

Django, how to create form for add/edit object with m2m links?

Good afternoon! There are three essences. Product, Option and ProductOption. Product has link many to many to Option through ProductOption. Prompt how to create please for Product'a the form of addition/editing with these options (not on administration page)? If simply to output {{product.options}} - will be SelectBox with a plural choi...

Saving a Django form to a csv file

I have a Django form that is working fine. I'd like to save the data it submits to a CSV file. Is there a "best practice" way to do this? I need to include blank fields in the CSV file where the user has not filled in a "required=False" field ...

Possible form field types per model field type

Django's documentation specifies for each model field type the corresponding default form field type. Alas, I couldn't find in the documentation, or anywhere else, what form field types are possible per model field type. Not all combinations are possible, right? Same question for widgets... ...

Odd behavior in Django Form (readonly field/widget)

I'm having a problem with a test app I'm writing to verify some Django functionality. The test app is a small "grade book" application that is currently using Alex Gaynor's readonly field functionality http://lazypython.blogspot.com/2008/12/building-read-only-field-in-django.html There are 2 problems which may be related. First, when ...

Manditory read-only fields in django

I'm writing a test "grade book" application. The models.py file is shown below. class Student(models.Model): name = models.CharField(max_length=50) parent = models.CharField(max_length=50) def __unicode__(self): return self.name class Grade(models.Model): studentId = models.ForeignKey(Student) finalGrade =...

Problem in adding custom fields to django-registration

I tried extending RegistrationFormUniqueEmail class CustomRegistrationFormUniqueEmail(RegistrationFormUniqueEmail): first_name = forms.CharField(label=_('First name'), max_length=30,required=True) last_name = forms.CharField(label=_('Last name'), max_length=30, required=True) def save(self, profile_callback=None): ne...

Overriding the default error message for a ModelForm

Is there any way to override a error_message text for all the fields of a ModelForm's, without having to include all the field info in the ModelForm? For example, let's say I have a (very simple) model like this: People(models.Model): name = models.CharField(max_length=128, null=True, blank=True, help_text="Please type your name."...

Django, ModelForms, User and UserProfile - not hashing password

I'm trying to setup a User - UserProfile relationship, display the form and save the data. When submitted, the data is saved, except the password field doesn't get hashed. Forms.py class UserForm(forms.ModelForm): username = forms.RegexField(label="Username", max_length=30, regex=r'^[\w.@+-]+$', help_text = "My text", error_messages =...

Django unique_together error and validation

class Votes(models.Model): field1 = models.ForeignKey(Blah1) field2 = models.ForeignKey(Blah2) class Meta: unique_together = (("field1","field2"),) I am using this code as one of my models. Now i wanted to know two things: 1. It doesn't show any error and it saved an entry which wasn't unique together; S...