Thursday, November 1, 2012

Re: how to semi-automate a choice in contrib.admin

On 2/11/2012 3:09pm, Mike Dewhirst wrote:
> If a user leaves a compulsory (blank=False) field empty in the Admin app
> I want to check the value of a different field and depending on that
> value either ...
>
> do nothing and let the system complain it needs data
>
> or
>
> fill in some appropriate data so it is no longer empty
>
> I have tried doing this in clean() on the model but without luck.
>
> On the other hand, clean() will happily insert my data if the field is
> adjusted to blank=True but that defeats the purpose of blank=False.
>
> How I can make the field blank=True and raise the exact same exception
> to emulate blank=False if the field is left empty when my logic says it
> should complain?

Raising a ValidationError in clean() when blank=True and the field is
empty does display the same error as if blank=False but ...

1. The error appears at the top of the page instead of just above the
field in question.

2. I can only get one error at a time.

Any suggestions?

Thanks

> Mike
>

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment