Maybe with celery and Django celery you can do what you want.  There is a
functionality called crontab that is manage by models with Django celery.
So you can create cron task that will call when you need with a reference
to you model.

As an interesting problem, think in the moment of update you model if you
use a cron task, specially when you change de date.



El lunes, 8 de febrero de 2016, Rod Delaporte <rod.delapo...@gmail.com>
escribió:
> I have a field of a model that changes states but I need to automatically
modify that value after an expiration datetime has come. Is there a way to
do this?
> Here is an example:
> class Post(models.Model):
> created_at = models.DateTimeField(auto_now_add=True)
> languages = (
>             ('1', 'active'),
>             ('2', 'inactive'),
>         )
> language = models.CharField(max_length=20, choices=languages,
default='english')
> duration = models.DurationField(blank=True, null=True)
> expires = models.DateTimeField(blank=True, null=True)
> updated_at = models.DateTimeField(auto_now=True)
> @property
> def active(self):
> return self.expires > localtime(now())
> def save(self, *args, **kwargs):
> self.created_at = localtime(now())
> self.expires = self.created_at + self.duration
> return super(Post, self).save(*args, **kwargs)
>
> The problem I have is that I have to call the active function property to
check if it's True or False and I'm looking for a way that this can be done
automatically so the database updates itself.
> I've been thinking about Django-cron but I can't chose when to call the
active function, this should be done for itself.
> Is this possible?
>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/87c2360f-b02c-42d4-ac33-d1dcdf4b852a%40googlegroups.com
.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
"La utopía sirve para caminar" Fernando Birri

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG%2B5VyMDOU313zLyQy8paopvuQA_TjBY9k0ZEXPigjsZ9qcr0Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to