Re: Complex validation
Actually, as a corollary to my previous question, I can't tell from
the Docs whether the model's validation process (in particular, the
clean() method) is called at save() or called when validating via a
form?
IE, I want the clean() method invoked at save - so that data imported
via fixtures or SQL is also validated. Should I move those validation
fields to the save method?
Cheers
L.
On 5 December 2013 15:04, Lachlan Musicman <datakid@gmail.com> wrote:
> Hola,
>
> I have an object Part that has a method part_number()
>
> part_number is a function that returns an identifying string based on
> a number of different vars on the model.
>
> part_number needs to be unique, but the building of the part_number is
> complex enough that it cannot just be done via class Meta:
> unique_together
>
> The model's clean():
>
> pn = self.part_number()
> all_parts = Part.objects.all()
> for part in all_pns:
> if pn == part.part_number():
> raise ValidationError('Part numbers must be unique.
> Part number %s already exists.' % part.part_number())
>
>
> It's fairly straight forward.
>
> Ideally I would like to make the %s in the error message to an <a>
> link for reference value.
>
> Is it possible to use/pass context data like that in a ValidationError message?
>
> eg:
>
> raise ValidationError(mark_safe('Part numbers must be unique. Part
> number %s <a href="parts/{{ part.slug }}'>already exists</a>.' %
> part.part_number()))
>
>
> cheers
> L.
>
>
> --
> From this perspective it is natural that anarchism be marked by
> spontaneity, differentiation, and experimentation that it be marked by
> an expressed affinity with chaos, if chaos is understood to be what
> lies outside or beyond the dominant game or system. Because of the
> resistance to definition and categorisation, the anarchist principle
> has been variously interpreted as, rather than an articulated
> position, "a moral attitude, an emotional climate, or even a mood".
> This mood hangs in dramatic tension between utopian hope or dystopian
> nihilism...
> -----
> http://zuihitsu.org/godspeed-you-black-emperor-and-the-politics-of-chaos
--
From this perspective it is natural that anarchism be marked by
spontaneity, differentiation, and experimentation that it be marked by
an expressed affinity with chaos, if chaos is understood to be what
lies outside or beyond the dominant game or system. Because of the
resistance to definition and categorisation, the anarchist principle
has been variously interpreted as, rather than an articulated
position, "a moral attitude, an emotional climate, or even a mood".
This mood hangs in dramatic tension between utopian hope or dystopian
nihilism...
-----
http://zuihitsu.org/godspeed-you-black-emperor-and-the-politics-of-chaos
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGBeqiPTYL%3DORUcKGyS8PA7BkdBK0i5k24x%3DycSB3%2BhRxegDKg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home