views:

36

answers:

2

Hi .. im wondering how to make some posted texts be deleted on some certain date/time on a django site. Is it done with scripts to delete content in the database?

+2  A: 

Yes, this is what management commands are for. You start these usually with a cronjob.

Further information: http://docs.djangoproject.com/en/dev/howto/custom-management-commands/

mawimawi
If you want to pass control of your cleanup tasks (or any cron-powered jobs), check out django-chronograph (http://github.com/t11e/django-chronograph) which lets you (or them) schedule and run django management tasks via the Admin. It's awesome
stevejalim
+2  A: 

I believe the most straightforward way to go about this is to hide the data to the clients. This is done by adding some expiration_date field to the model. Then you may have a custom manager that looks like:

class ValidObject(Manager):
    def filter_valid(self):
        return self.filter(expiration_date__gt=datetime.date.today())
Olivier