3👍
✅
You can use django-auditable-models for that. It will hook in the django workflow, and will avoid that you have to write all logic yourself.
👤Ward
0👍
You can use loggers in Django.
https://docs.djangoproject.com/en/1.8/topics/logging/#topic-logging-parts-loggers
- [Django]-How do you produce/create tables in Geraldo Reports?
- [Django]-How do I paginate WeekArchiveView?
- [Django]-Optimize multiple Views to one View – Django
- [Django]-Django WSGI deployment. cannot import name 'SimpleCookie'
- [Django]-How to redirect to a newly created object in Django without a Generic View's post_save_redirect argument
0👍
To log something like that I recommend you to create an core
app with a TimeStampModel
model:
from django.db import models
from django.utils.timezone import now
class TimeStampModel(models.Model):
"""
TimeStampModel class allows us to follow creation and update of each inherit instance
"""
created_at = models.DateTimeField(auto_now_add=now(), editable=False)
updated_at = models.DateTimeField(auto_now=now(), editable=False)
class Meta:
abstract = True
Now, inherit each models from TimeStampModel
that you want to record creation or update date.
E.g:
from django.db import models
from core.models import TimeStampModel
class Token(TimeStampModel):
uuid = models.CharField(max_length=255, primary_key=True)
# ...
You can also add a delete
attribute (Boolean) to realize logical delete. And the last update, will be the date of deletion.
Two Scoops of Django 1.8 recommends also this practice.
- [Django]-Django Admin Custom Widget for ForeignKey
- [Django]-Django admin – how to hide some fields in User edit?
- [Django]-Django Permission Required
- [Django]-How to edit field in django admin panel
Source:stackexchange.com