On Jul 25, 3:57 pm, Javier Guerra Giraldez <jav...@guerrag.com> wrote:
> On Mon, Jul 25, 2011 at 2:50 PM, webcomm <rya...@gmail.com> wrote:
> > try:
> >  self.id
> > except NameError:
> >  # run this code if it is a new item
> > else:
> >  # run this code if this is a previously saved item
>
> works, but it's nicer to use "if hasattr(obj,field): ...."

Thanks.  Any idea why the following isn't working in my News class?
The processing doesn't get to that exit call, even if it's a new item.

    def save(self, *args, **kwargs):
        if not hasattr(self,'id'):
            import sys
            sys.exit('must be a new item')
        super(News, self).save(*args, **kwargs)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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