django-forms

Trying to update a form it does an insertion!

I'm trying to update an object, but I'm getting: "primary key must be unique"... The model for Entry: class Entry(models.Model): title = models.CharField(max_length=250) author = models.ForeignKey(User, editable=False) status = models.IntegerField(choices=data_types.STATUS_CHOICES, default = data_types.STATUS...

How can I use django forms/models to represent choices between fields?

How can I use boolean choices in a model field to enable/disable other fields. If a boolean value is true/false I want it to enable/disable other model fields. Is there a way to natively express these relationships using django models/forms/widgets? I keep writing custom templates to model these relationships, but can't figure out a g...

Django - How to preopopluate admin form fields

I know that you can prepopulate admin form fields based on other fields. For example, I have a slug field that is automatically populated based on the title field. However, I would also like to make other automatic prepopulations based on the date. For example, I have an URL field, and I want it to automatically be set to http://www.mys...

django form variable

I have spent too much time on this problem and am beginning to think that it can't be done in Django. I am pulling a list of pathogen names from a postgres database to a drop down box. The user selects the pathogen, which requires the id to be passed back through django to the database for further retrieval of more data. Please see h...

Django: How can I put an <a> hyperlink in a django validation error from a forms clean() method?

Django: How can I put an <a> hyperlink in a django validation error from a forms clean() method? I want to raise a validation error, and in the error text have an <a href=""></a> hyperlink that has a link that would help the user correct the error. This is a validation error I'm raising in a clean method of a form. Is there a way to m...

Banned IPs in Django form validation

I am trying to validate a form, such that if IP of user (request.META['REMOTE_ADDR']) is in a table BlockedIPs, it would fail validation. However I don't have access to request variable in Form. How do I do it? Thanks. ...

Suggested Method to Forward POST Parameters Through login_required Decorator?

Hello, I am currently having the problem that when I use the login_required decorator from django.contrib.auth.decorators on any of my views, my POST parameters do not arrive at the protected view whenever the decorator did redirect (to the login page) and back again to the protected view. Suggestions about how to work around this (pre...

Setting values to the output of a formset in Django

This question is somewhat linked to a question I asked previously: http://stackoverflow.com/questions/477183/generating-and-submitting-a-dynamic-number-of-objects-in-a-form-with-django I'm wondering, if I've got separate default values for each form within a formset, am I able to pre-populate the fields? For instance, a form requiring ...

Django: multiple models in one template using forms

I'm building a support ticket tracking app and have a few models I'd like to create from one page. Tickets belong to a Customer via a ForeignKey. Notes belong to Tickets via a ForeignKey as well. I'd like to have the option of selecting a Customer (that's a whole separate project) OR creating a new Customer, then creating a Ticket and fi...

How do I add plain text info to forms in a formset in Django?

I want to show a title and description from a db query in each form, but I don't want it to be in a charfield, I want it to be html-formatted text. sample template code: {% for form, data in zipped_data %} <div class="row"> <div class="first_col"> <span class="title">{{ data.0 }}</span> <div class="desc"> ...

Adding data to many-to-many field of a modelform within a view

class Person(models.Model): name = models.CharField(max_length=100) class Entry(models.Model): text = models.CharField(max_length=100) person = models.ManyToManyField(Person, blank=True, null=True) class MyModelForm(forms.ModelForm): class Meta: model = Entry In my view, I need to add pk id's to a submitted fo...

Django ForeignKey on form with ModelChoiceField disappears

Weird problem in Django with forms : I have a Form.class defined like this ... class MeetingForm(forms.Form): owner = forms.ModelChoiceField( queryset=Profile.objects.all(), widget=forms.HiddenInput() ) date = forms.DateTimeField() name = forms.CharField(max_length=30) etc. And I create new ins...

What is the best way to represent a schedule in a database, via Python/Django?

I am writing a backup system in Python, with a Django front-end. I have decided to implement the scheduling in a slightly strange way - the client will poll the server (every 10 minutes or so), for a list of backups that need doing. The server will only respond when the time to backup is reached. This is to keep the system platform indep...

Django Passing Custom Form Parameters to Formset

I have a Django Form that looks like this: class ServiceForm(forms.Form): option = forms.ModelChoiceField(queryset=ServiceOption.objects.none()) rate = forms.DecimalField(widget=custom_widgets.SmallField()) units = forms.IntegerField(min_value=1, widget=custom_widgets.SmallField()) def __init__(self, *args, **kwargs): ...

[django] resize image on save

How can I easily resize an image after it has been uploaded in Django? I am using Django 1.0.2 and I've installed PIL. I was thinking about overriding the save() method of the Model to resize it, but I don't really know how to start out and override it. Can someone point me in the right direction? Thanks :-) @Guðmundur H: This won't w...

How do I make a Django ModelForm menu item selected by default?

I am working on a Django app. One of my models, "User", includes a "gender" field, as defined below: GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female'), ) gender = models.CharField(max_length=1, choices=GENDER_CHOICES, null=True) I am using a ModelForm to generate a "new user" HTML form. My Google-fu seems to be fai...

Django Form Preview - Adding the User to the Form before save

class RegistrationFormPreview(FormPreview): preview_template = 'workshops/workshop_register_preview.html' form_template = 'workshops/workshop_register_form.html' def done(self, request, cleaned_data): # Do something with the cleaned_data, then redirect # to a "success" page. # data = request...

Django forms: help with styling forms

Hi stack overflow, I'm trying to style a form with CSS. First of all I haven't seen a complete example, other than on the official documentation, so I would appreciate any blog entries, or articles. Now on my form, a typical Charfield gets translated on html like this: input type="text" name="artists" id="id_artists" If my form cont...

Form Field API?

I am iterating through list of form fields. How do I identify the type of each field? For checkbox I can call field.is_checkbox...are there similar methods for lists, multiplechoicefields etc. ? Thanks ...

Django Form Preview - How to work with 'cleaned_data'

Thanks to Insin for answering a previous question related to this one. His answer worked and works well, however, I'm perplexed at the provision of 'cleaned_data', or more precisely, how to use it? class RegistrationFormPreview(FormPreview): preview_template = 'workshops/workshop_register_preview.html' form_template = ...