django-forms

When editing an object in django the ImageField is not populated

I'm trying to edit an existing object through a form. Every thing is working fine except for the ImageField not being populated with the current value. Here's the model: class Post(models.Model): author = models.ForeignKey(User, editable=False) slug = models.SlugField(max_length = 110, editable=False) title = models.CharFi...

Implementing USZipCodeField and USStateField in django

I'm looking to implement a zipcode field in django using the form objects from localflavor, but not quite getting them to work. I want to have a zipcode field in a form (or ModelForm in my case), but the fields never validate as a zipcode when calling _get_errors() on the form object. The way I'm implementing it seems right to me but is...

django modelformset_factory - how to add a field in the view after commit=False + ignore empty forms

Hi, I create a FormSet with modelformset_factory. HourRecordFormSet = modelformset_factory(HourRecord, max_num=6, extra=3, form=HourRecordBatchForm) Then I want to set the project field of a certain HourRecord object to the actual project. This should be done in the view. I tried it like this. if hour_record_formset_january.is_val...

Django - split large model using FormWizard

Hello, I am a python/django newbie trying to accomplish the task below. Any help will be greatly appreciated. I have a model with around 50 or so fields. I need to break them up and provide a wizard like functionality. class ABC(models.Model): field_1 = models.IntegerField('Field 1') field_2 = models.CharField('Field 2') .. ...

[Django] Registration Form with only email + password

I want a Registration Form with only email + password. I am thinking to insert automatically email in username field. So, for eash user, I will have this: username: [email protected] password: mypassword email: [email protected] Of course email + password will be used in login process. Is it a good solution to having 2 fields...

[Django] Insert AUTOMATICALLY random string in username field

I want username field is automatically filled with this value: username = str(n); where n is a number ( autoincremented or random ). . I tried to add this in save method: username = str(random.randint(0,1000000) but there is a collision problem when n is the same for 2 users. . How do I do this ? Thanks ^_^ ...

[Django] How insert id in username field

I want username field automatically filled with this: username = email[0] + str(id) where id is the id of the user object Is it possible ? Thanks :) ...

How to catch Django request.GET error?

This view works when the query is in the database. def search(request): if 'q' in request.GET and request.GET['q']: q = request.GET['q'] q_school = Lawyer.objects.filter(last__icontains=q).values_list('school', flat=True) q_year = Lawyer.objects.filter(last__icontains=q).values_list('year_graduated', flat=Tru...

Django forms: How do I get first and last names from an HTML form?

At present the search form is for last name only and that causes problems where there are more than one last name. This was noted here by Antony Hatchkin. To solve the problem I want to add a search form with last name and first name and write a new search function search2(). Will the new function look something like this? def search...

"recipient" from form in send mail

I have a very basic email app. The forms class is: class ContactForm(forms.Form): name = forms.CharField(max_length=100) subject = forms.CharField(max_length=100) sender = forms.EmailField() recipient_list = forms.EmailField() message = forms.CharField(widget=forms.Textarea) cc_myself = forms.BooleanField(initial...

Django ModelForm: adding an alias to a field

I have a (GoogleAppEngine) Django ModelForm: class A(db.Model): a = db.StringProperty() class MyAForm(djangoforms.ModelForm): class Meta: model = A This creates a form which has one string field a. On my form I'd like to call this something else, say b. So I'd like a form with a field called b and when the form is POSTed we ...

Custom Django admin widgets for many-to-many relations

Let's say I have the following Django models with these ForeignKey fields (simplified syntax): class Container(Model): items -> Item sub_items -> SubItem sub_sub_items -> SubSubItem class Item(Model): container -> Container children -> SubItem class SubItem(Model): container -> Container parent -> Item ...

Django Form Submit Button

I have a pretty simple file upload form class in django: class UploadFileForm(forms.Form): category = forms.ChoiceField(get_category_list()) file = forms.FileField() one problem is that when i do {{ form.as_p }}, It has no submit button. How do i add one? ...

Hidden field in Django Model

A while back I made a Model class. I made several ModelForms for it and it worked beautifully. I recently had to add another optional (blank=True, null=True) field to it so we can store some relationship data between Users. It's essentially a referral system. The problem is adding this new field has meant the referral field shows up wh...

Extended Form silently fails

Hello, SOvians. I have customized one of my forms and now it does not pass the is_valid() test. No form.errors are visible. Any ideas for where I went wrong? Form: class SearchForm(forms.Form): param = forms.CharField(required=False, max_length = 500, label = 'Search for') sets = forms.ModelMultipleChoiceField(queryset=Set.obje...

Two forms in django templates without conflict

hi, I'm creating a template with two different forms but I have the following problem: when I submit the first one the second is also validated and get validation errors. What can I do to avoid this conflict? Thanks and sorry for my english. ...

Access Image through (Model)Form Field (was: Image Preview in (Model)Form)

Hi, can I access an image via a form-field in the template? <p> {% if field.errors %} <span class="error">{{ field.errors }}</span> {% endif %} {{ field.label_tag }}:<br /> <img src="{{ field.value.url }}" /> {# <- This is what I want to do, I know it doesn't work like this #} {{ field }}<br /> <span >{{ field.help_text }}</span> <...

Django: Would models.Field.validate() for all validation save a lot of code writing?

Am I thinking about this all wrong, or am I missing something really obvious? Python's style guide say's less code is better (and I don't think that's subjective... It's a fact), so consider this. To use forms for all validation means that to write a model field subclass with custom validation, you'd have to: Subclass models.Field Su...

Django: Overriding the clean() method in forms - question about raising errors

I've been doing things like this in the clean method: if self.cleaned_data['type'].organized_by != self.cleaned_data['organized_by']: raise forms.ValidationError('The type and organization do not match.') if self.cleaned_data['start'] > self.cleaned_data['end']: raise forms.ValidationError('The start date cannot be later tha...

django - how to check in a clean method of a form whether it is an insert or an update

Hi, I have a form where I validate in the clean method whether a ProjectMembership object already exist, that has the same values for project and member. This is due that I have in the ProjectMembership model defined a unique_together constraint for project and member. This works fine actually. class ProjectMembershipForm(forms.ModelF...