django-validation

Django validation array of errors

I am using rf['email'].errors As said in docs, I can use it to have array of errors. [str(e) for e in rf['email'].errors] #give me ["<django.utils.functional.__proxy__>"] If repr or str - it gives ul's or string of array. So it worked only when I used repr and eval together. But I think its stupid solution. eval(`rf['email'].e...

Django models overriding save / use a signal / or use a modelform?

I realize this has been asked before, but I wasn't able to find a question that really dealt with what I'm trying to do. I think it's pretty simple, but I'd like to know what the general population thinks is best form here. Lets say we have the following: models.py class TestClass(models.Model): user = models.ForeignKey(User) ...

how validate form and show the value of the filled fields?

Hi guys, now im learning to validate form, "all" is working, im showing the erros of empty fields, but i have 2 questions: how ill show the value in the filled fields when there are errors in another fields?, like <input ... value= {{ value }} > the problem is that my fields are not html forms fields. how ill show the error exactly ove...

Django validate and go back to preview URL ?

Hi guys, im asking again :), i don't know how make this. My English is not too good, but ill try to asking this: how ill validate a form and go back to the preview url (the same view form) and show the validation errors?, im asking this because i have 2 form's, the first form's action is going to a second form (POST), but in this secon...

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 Custom Model Field with Validation...how to hook it back to ModelForm

Hello... A common occurrence I have with one particular project is that it requires the user to enter dimensions (for width/depth/height) in Feet and Inches. Calculations are needed to be performed on that dimension, so I've been working on a custom field type that takes in a dimension in Feet/Inches (eg. 1'-10") and saves it to the dat...

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: Does model_instance.clean() run before basic validators?

Let's say that I have a model: class Ticket(models.Model): client = models.ForeignKey(Client) color = models.CharField(max_length=255) def clean(self): self.color = self.client.favorite_color When I run this on the latest Django (head of the SVN from 15 minutes ago), if I hit save without selecting a client, I get...

Django 1.1.1, need custom validation dependant on other fields

I have 3 models in a Django app, each one has a "hostname" field. For several reasons, these are tracked in different models.: class device(models.Model): ... hostname = models.CharField(max_length=45, unique=True, help_text="The hostname for this device") ... class netdevice(models.Model): ... hostname = models.CharField(max_length=4...

Django - How best to handle ValidationErrors after form.save(commit=False)

This is a fragment of my code from a view: if form.is_valid(): instance = form.save(commit=False) try: instance.account = request.account instance.full_clean() except ValidationError, e: # Do something with the errors here... I certainly don't want to do this 180 times. T...

Django: one form for two models (solved)

UPDATE The issue is solved, all the code you can see works. Hello! I have a ForeignKey relationship between TextPage and Paragraph and my goal is to make front-end TextPage creating/editing form as if it was in ModelAdmin with 'inlines': several fields for the TextPage and then a couple of Paragraph instances stacked inline. The proble...

Django Formset validation with an optional ForeignKey field

Having a ModelFormSet built with modelformset_factory and using a model with an optional ForeignKey, how can I make empty (null) associations to validate on that form? Here is a sample code: ### model class Prueba(models.Model): cliente = models.ForeignKey(Cliente, null = True) valor = models.CharField(max_length = 20) ### vi...

Django TextField max_length validation for ModelForm

Hi, Django does not respect the max_length attribute of TextField model field while validating a ModelForm. So I define a LimitedTextField inherited from the models.TextField and added validation bits similar to models.CharField: from django.core import validators class LimitedTextField(models.TextField): def __init__(self, *arg...

Adding an error to a django form in a view... hack?

What I'm trying to do is to add an error for a field in a view, AFTER both form.is_valid() and form.save(), and it seems to work but only because of a hack, and I'm hoping someone here can explain why it works. So in my form's save() function, I connect to an LDAP server, and try to authenticate the user and password supplied in the for...

Django and testing local URLs exist

I have a model which needs to store URLs which will be part of the Django environment. If I was storing normal URLs, I'd use models.URLField, and use verify_exists to make sure the URL actually exists. However, this doesn't work that great in development, since the dev server is single-threaded, it hangs indefinitely, since it can't pro...

How can I create sophisticated Django Model Validation for Django Admin?

I have the following model in Django: class Bout (models.Model): fighter_1 = models.ForeignKey(Fighter, related_name="bout_fighter_1") fighter_2 = models.ForeignKey(Fighter, related_name="bout_fighter_2") winner = models.ForeignKey(Fighter, related_name="bout_winner", blank=True, null=True, help_text='Leave blank fo...

How to check value transition in Django (django-admin)? (Revisited)

I was wondering about how to control transitions in model data. I found the solution at http://stackoverflow.com/questions/867120/how-to-check-value-transition-in-django-django-admin but when I tried to implement it within my code, something went wrong (I am able to change the status with impunity): Here is the relevant portion of my ...

Validate/clean a FileField on a non-model form in Django?

I'm ultimately trying to validate a FileField by extension type. But I'm having trouble even getting the clean method for this field to pickup the POSTed value. from django.forms.forms import Form from django.forms.fields import FileField from django.forms.util import ValidationError class TestForm(Form): file = FileField(r...