Package: django-record
AuthorHa JunsooRequirementsTested against Python 2.7 and 3.4django-recordsupportsdjango1.7 or later.Requirespandas0.17.0 or later.Requiresfakerfor tests.Installationpip installdjango-recordRationaleOften there are situations where you want to record your properties of your models and
where you want to track their changes. Although that recording process can be implemented
byhandcrafted, ad-hoc signalsoroverriding save() methods of your models, it’s
not a generic way, andit’ll eventually mess up your code base.django-recordautomatically creates an snapshot-like extra recordwhen an audited
Django model instance has been changedeither directly or indirectly,
without messing up your code base.RecordModelwill detect any changes inrecording_fieldsofrecording_modelat it’spost_savetime orauditing_relatives’spost_savetime and create an new record for it.You can access records via record managerrecordsin your recorded model
instance. You can also access recorded model’s instance viarecording,
which is in effect just ordinaryForeignKey, from your records.More conveniently,just mixRecordedModelMixininto your model and providerecording_fieldsandauditing_relatives.Usagefromdjango.dbimportmodelsfromdjango_record.mixinsimportRecordedModelMixinclassMyTopic(models.Model):title=models.CharField(max_length=100)classMyArticle(RecordedModelMixin,models.Model):topic=models.ForeignKey(MyTopic)text=models.TextField()@propertydefmy_local_property(self):returnself.text@propertydefmy_nonlocal_property(self):returnself.topic.title+self.text# We will monitor `topic` relative to watch if he changes!auditing_relatives=['topic']recording_fields=[# Record changes of the model instance's `text` field'text',# Yayy! we can record changes on properties too!('my_local_property',models.TextField()),# Even indirect effects from relatives are recordable!('my_nonlocal_property',models.TextField())]# To get the model instance's all records>>>my_article.records.all()# To get queryset of the model instance's records created in specific# time threshold>>>my_article.records.created_in_years(2)>>>my_article.records.created_in_days(3)>>>my_article.records.created_in_minutes(5)# To resample records of today by hour>>>my_article.records.created_in_days().resample('T')# To get record contents>>>my_article.records.first().text>>>my_article.records.first().my_local_property>>>my_article.records.first().my_nonlocal_propertyNoteRecursive auditing is currently not supported.Indirect effect only those
from direct relatives will be detected and recorded.Only primitive types are supported for properties.You must offer appropriate django field for them.RecordModelis also a subclass ofTimeStampedModel, so make sure that
you don’t record either ‘created’ or ‘modified’ fields.Changes11.09.2015 (0.2.5 release)Renamed TimeStampedModel to AbstractTimeStampedModel.Replaced monkey patched shortcut properties withRecordQuerysetfilters.
Those shortcut properties are now deprecated.09.20.2015Support Python 3.406.13.2015Following shortcut properties added torecording_model. All of properties
below are ordinary django querysets.records_in_hour: Records created in last recent hour.records_in_day: Records created today.records_in_week: Records created in this week.records_in_month: Records created in this month.records_in_year: Records created in this year.Following shortcut properties providing resampled records has been added torecording_model.  All of properties below are ordinary django querysets.resampled_records_in_hour: Records created in last recent hour,
resampled with minutes.resampled_records_in_day: Records created today, resampled with hours.resampled_records_in_week: Records created in this week, resamped with
days.resampled_records_in_month: Records created in this month, resampled
with days.resamped_records_in_year: Records created in this year, resampled with
months.05.18.2015RecordedModelMixinadded.