On Tue, 2006-07-04 at 02:11 +0000, DavidA wrote:
> 
> Malcolm Tredinnick wrote:
> > On Mon, 2006-07-03 at 08:54 -0700, Glenn Tenney wrote:
> > > Perhaps instead of relying on the behavor of the object's ID not
> > > existing until it's been created, that should become a method.
> > > something like Model.created() returning true/flase or Model.is_created
> > > or... something...???
> >
> > I can't see any real advantage in this. As Ivan shows, it's only a
> > couple of lines of code anyway (and a more or less documented feature).
> > The boolean test for "not created" at the moment is "if not self.pk:",
> > which seems pretty reasonable.
> 
> But doesn't that assume you are using an auto-generated ID column? What
> if my model looked like this:
> 
> class Post(models.Model):
>     slug = models.SlugField(prepopulate_from=('title',),
> primary_key=True)
>     title = models.CharField(maxlength=80)
>     body = models.TextField()
> 
> In this case it would be up to the app or developer to populate the
> slug primary key field before saving. But then just testing the pk
> field wouldn't really tell me if it was saved, unless I misunderstand
> what "self.pk" is actually doing behind the scenes.
> 
> I'll admit, my example is what I would consider bad form, but its valid
> and I only point this out as I've seen it used.

An excellent point. :-)

I'm not sure a created() method is going to be the right API, since this
event has very transitory relevance, but your example does suggest we
may need something extra here at some point.

Best wishes,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to