On Feb 24, 9:55 pm, Timothy Kinney <timothyjkin...@gmail.com> 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 django-us...@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.

Reply via email to