I have a model something like,

class Task(models.Model):
  name = models.CharField()
  parent_task = models.ForeignKey('Task')
  is_complete = models.BooleanField()

class TaskItem(models.Model)
  name = models.CharField()
  task = models.ForeignKey(Task)
  is_complete = models.BooleanField()

I have written a lot of code using this model. Now I need to change
the code so that whenever the is_complete is set, we should have some
more effects. So I am trying to use
is_complete = property(get_is_complete, set_is_complete) so that I can
have side effects when is_complete is set. But after this call as
is_complete is not a models.Field subclass a number of things break.
(For example forms.ModelField). Is there some way I can achieve this
effect.

---------
My code looks like this,

def set_is_complete(self, value):
        """If a task is marked as complete all its sub tasks and task
items should be marked as complete."""
        self.is_complete = value
        #self.save()
        if not value:
            cursor = connection.cursor()
            cursor.execute('UPDATE project_task SET is_complete = %s
WHERE parent_task_id = %s' % (False, self.id))
            cursor.execute('UPDATE project_taskitem SET is_complete =
%s WHERE task_id = %s' % (self.id))

    def get_is_complete(self):
        return self.is_complete

    is_complete = property(get_is_complete,
set_is_complete)
--~--~---------~--~----~------------~-------~--~----~
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