On Wed, Feb 24, 2010 at 5:13 PM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:
> But anyway: you already specified the unique constraint in the 'name'
> field definition, so adding this code in your model save() method is
> just useless - the uniqueness constraint WILL be applied at
On 24 fév, 21:11, harryos wrote:
> sorry,
> missed while copying
>
> def save(self):
> self.name=self.name.strip()
> if (not self.pk):
> if Article.objects.filter(name__iexact=self.name).count()!
> =0:
> raise Exception('article exists..')
Now this will only
sorry,
missed while copying
def save(self):
self.name=self.name.strip()
if (not self.pk):
if Article.objects.filter(name__iexact=self.name).count()!
=0:
raise Exception('article exists..')
this causes 500 error,and causes the traceback displayed on
browser..h
Note:
As written, your code will never let you edit an existing Article. You should
add an if statement to check whether 'self.pk' is true also.
Shawn
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to djang
hi
In my models save() method I want to check if an Article with same
name already exists.
class Article(Model):
name=models.CharField(max_length = 1024, unique = True)
def save(self):
self.name=self.name.strip()
if Article.objects.filter(name__iexact=self.name).count()!=0:
5 matches
Mail list logo