I'm trying to come up with the best working solution to allow my
application to save subsequent objects when I save an object. Here's my
model:


class Milestone(models.Model):
    """Catalogue of project milestones"""
    ...
    deadline = models.DateField()
    ...

    def save(self):
        user = threadlocals.get_current_user()
        posted = threadlocals.get_post_data()
        
        if self.id:
           if posted.has_key('shift_in_future') and posted['shift_in_future'] 
== 'on':
               oDeadline = 
datetime.date(*time.strptime(posted['original_deadline'], '%Y-%m-%d')[:3])
               nDeadline = datetime.date(*time.strptime(posted['deadline'], 
'%Y-%m-%d')[:3])
               interval = timedelta(nDeadline - oDeadline)

                future_milestones = Milestone.objects.filter(deadline__gte = 
oDeadline)
                for f in future_milestones:
                    f.deadline = f.deadline + interval
                    super(Milestone, f).save()
        
        self.editor = user
        super(Milestone, self).save()
        
        
# threadlocals.py middleware
try:
    from threading import local
except ImportError:
    from django.utils._threading_local import local

_thread_locals = local()

def get_current_user():
    return getattr(_thread_locals, 'user', None)

def get_post_data():
    return getattr(_thread_locals, 'POST', None)

class ThreadLocals(object):
    """Middleware that gets various objects from the
    request object and saves them in thread local storage."""
    def process_request(self, request):
        _thread_locals.user = getattr(request, 'user', None)
        _thread_locals.POST = getattr(request, 'POST', None)



Well, it doesn't work, and I'm not sure if this is the best way to do
this. Any ideas from those who would know more and how to achieve this?


--~--~---------~--~----~------------~-------~--~----~
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