سؤال

I have some Django models that store custom log and query data that I only want to keep for a limited time (i.e. 30 days of search data or a max of 10,000 database rows of logging data). The models are used in visualization views, so not something I could just store in a file and let logrotate handle.

Is there anything built into Django to handle this?

I'm OK with creating a cron job that uses SQLAlchemy to periodically prune the database, or with creating an admin-only page that prunes the records (via the view code) when visited, but if there's something already built into Django to handle limited data retention it might make more sense to use that.

هل كانت مفيدة؟

المحلول

Create a custom django-admin command for your app that purges old records, then have cron run it periodically. I suppose you could use SQLAlchemy, but I don't know why you wouldn't just use django's ORM.

Your command would be very similar to the django sessions clearsessions command. Its source code could be useful.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top