> This won't work with the admin interface, because it wouldn't know
> about your set_posted() method. With that said, you might be able to
> use Python properties, but I have never tried that and am not sure
> whether it would work. If it did work, you could do this:
> 
> class Entry(models.Model):
>     post_date = models.DateTimeField(...)
>     posted = models.BooleanField(...)
> 
>     def set_posted(self, new_value):
>         if new_value != self.posted:
>             self.post_date = datetime.datetime.now()
>     posted = property(set_posted)

Note that the property built-in takes the "getter" as the first,
required argument and the "setter" as the optional, second argument.  So
if you were going to do this with properties you'd want to do:

class Entry(models.Model):
    post_date = models.DateTimeField(...)
    posted = models.BooleanField(...)

    def get_posted(self):
        return self.posted

    def set_posted(self, new_value):
        if new_value != self.posted:
            self.post_date = datetime.datetime.now()

    posted = property(get_posted, set_posted)

I'm also not sure how Django would interact with having the posted model
field effectively masked by the new property, so you might want to call
your property w/ extra set functionality something different.  YMMV.

Nathan

> 
> ...and any time you set the "posted" attribute, it would call
> set_posted() behind the scenes. Like I said, though, I'm not sure
> whether that would work with the way models are currently implemented.
> (But if not, let's go ahead and fix that!)
> 
> Adrian
> 


--~--~---------~--~----~------------~-------~--~----~
 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to