As far as requiring a unique value you can set this in your model. 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. On
the other hand, if you have something like first names and last names you
might want to allow each name to be duplicated but not allow them to be
duplicated together (So there could be two Tims and two Mr. Kinneys, but
only one Tim Kinney, for example). Then you use the Meta class like this:

class MyModel(models.Model):
   # do stuff
    class Meta:
        unique_together = ("field_name_1", "field_name_2")


Once you've defined which values need to be unique, you can then check for
the exception that is raised and inform the user to try a different entry,
or you can use an error message system like the Admin view uses for entering
forms. I recommend the latter, but it takes a little more work to
understand.

In general, set up your models so that the database is doing all the
integrity checking for you. This simplifies your design and lets you
concentrate on presenting content in a useful way.

-Tim


On Wed, Feb 24, 2010 at 10:03 AM, Shawn Milochik <sh...@milochik.com> wrote:

> There's no need to pass 'instance' if you're instantiating your ModelForm
> with request.POST. You only need to pass the instance if you already have a
> specific model instance programmatically and want to get a ModelForm for it.
>
> You can replace if request.method=='POST': with if request.POST:
>
> Adding a clean function to your ModelForm should take care of all that
> stripping for you. Something like this:
>
>    def clean_name(self):
>
>        name = self.cleaned_data['name']
>        return name.strip()
>
>
> I hope this helps.
>
> Shawn
>
> --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> 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 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