You can define a variable called error_message which is None when you pass
it into the template initially. Then you can fill it with the desired
message and do something like this:
{% if error_message %}
# display some information
-Tim
On Wed, Feb 24, 2010 at 11:16 AM, jimgardener <[email protected]> wrote:
>
>
> On Feb 24, 9:55 pm, Timothy Kinney <[email protected]> wrote:
> >Just add
> > the option *unique=True* when you define the field in the model and the
> > database will not allow two entries with the same value for that field.
>
>
> I have defined the name field to be unique in the model.
> name=models.CharField(unique=True,max_length=50)
> if I try to give ' python' as subject name and that would cause an
> IntegrityError if a subject already has name 'python'.
> I have defined the clean_name() method to do stripping of spaces as
> Shawn advised.
>
>
> Now,using subject_is_new(name) I am checking whether an object of
> that name exists and calls form.save() only if the check returns True.
> But my problem is the else branch as shown in my code.I am not sure
> how I can modify the description field of the existing subject
> (please see below)
>
>
> <snippet>
> if form.is_valid():
> subname=form.cleaned_data['name']
> if subject_is_new(subname):
> form.save()
> else:
> #HOW TO DO THIS? I need to update the description
> field
>
> <snippet>
>
> class SubjectForm:
> ...
> def clean_name(self):
> name=self.cleaned_data['name']
> name=name.strip()
> return name
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<django-users%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.