referencing the object id from clean validation methods

2009-05-16 Thread simon101

Hi

I am using ModelForms to create forms from the models, and using the
clean_field and clean methods to validate the fields and form data as
a  whole.  I get the self.cleaned_data[] dictionary which contains all
the cleaned up data from the html form, but  it doesn't contain the id
for the object id for the object which the ModelForm pulled it off.

Anyone got any ideas how to fix this?  My code looks like this.

class Contract(db.Model):
storage_required = db.BooleanProperty
(verbose_name="storage_required")

class ContractForm(ModelForm):
storage_required = fields.BooleanField()

class Meta:
model = Contract

def clean_storage_required(self):
stor_req = self.cleaned_data['storage_required']
obj_id = ?

btw I am using gae but this shouldn't affect this I think.

Thanks guys

Simon
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



looping through form.errors in templates

2009-05-17 Thread simon101

Hi

I've noticed that there have been changes in form error processing for
templates when I've been updating some old code to work with django
1.0.2 from 0.96. My code for displaying errors at the top of the pages
looked like this in 0.96:

{% if form.has_errors  %}
Please correct the following error{{ form.error_dict|
pluralize }}:

{% for elem in form.error_dict.items %}
{{ elem.0 }}: {{ elem.1.0 }}
{% endfor %}

{% endif %}

I've had to replace form.has_errors with form.errors, as shown below:

{% if form.errors %}
Please correct the following error{{ form.errors|pluralize }}:

{% for elem in form.errors %}
{{ elem }}: 
{% endfor %}

{% endif %}

However the new code shown above only displays the field name and not
the actual error text.  What's the syntax for showing the actual error
message on form.errors.

Thanks for any help

Simon
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



problem with custom validator and booleanfields

2006-09-24 Thread simon101

Hi

I have a model with a boolean field which has a custom validator
defined in the validator_list parameter.  The validator has to run
whenever the form is submitted, whether the checkbox is ticked or not.
I have set the 'always_test' parameter to true for the validator, but
the validator still only gets called when the box is ticked.  I have
found that the 'always_test' parameter works fine for other types of
field, it just appears to be a problem with booleanfields.   Relevant
sections of the model are pasted below:

class Order(models.Model):

def stor_all(field_data, new_data):
   ..validator code goes here
stor_all.always_test = True

   storage_all = models.BooleanField('All to be delivered to
storage?', null='true', validator_list = [stor_all])

Has anyone else encountered this problem and is there a fix for it?

Thx in advance for any help.

Simon


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



validator_list with checkboxes

2006-09-25 Thread simon101

My first post, so hi everybody.

I have a model that has a checkbox field called storage_Required.  The
field has a custom generator defined  in the validator_list parameter.
The validator needs to be  run whenever the form is submitted, whether
the checkbox is ticked or not.   Unfortunately the validator is  only
run when the checkbox is ticked.   I have tried defining the
always_test parameter to true, but this doesn't seem to work for
checkboxes, although it works fine for other types of field.  Relevant
code is posted below:


class Order(models.Model):

def stor_valid(field_data, new_data):
..  code here
stor_valid.always_test = True

storage_Required = models.BooleanField(null='true', validator_list
= [stor_valid])

Has anyone else encountered this problem?  If so is there a ticket
outstanding with a patch available, or am I just missing something
really stupid here?

Thx in advance for any help.

Simon


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---