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