A
A
Alexander2019-06-13 11:48:45
Django
Alexander, 2019-06-13 11:48:45

What is the best way to make history model in Django?

Hey!
Background : a small django service parses resources, receives objects that need to be filtered according to different criteria, sequentially, leaving only suitable ones. There are many resources, there are many objects on the resources, there are about 5-7 criteria (filters).
Task : I wanted to keep a detailed log (and not just in the filter.log file) so that I could analyze which filters in which resources filter information most often and how often.
For this, a simple model was created:

class FilterHistory(models.Model):
    created_at = models.DateTimeField(auto_now_add=True, editable=False)
    source = models.ForeignKey(Source, on_delete=models.CASCADE, related_name='history')
    filter_name = models.CharField(max_length=100, default='unknown')
    filtered_number = models.IntegerField()

And after all the filtering, information was stored for each filter.
Problem : it is difficult to analyze this, since the initial number of objects is not saved and the order of the filters is not taken into account in the logs (only by time). Especially in django admin. I can't think of a good solution right off the bat to meet the requirements.
I thought that there should be another model that contains the basic information about the filtering session, related to the models of individual filters (one-to-many). Type: History -> HistoryItems
Please help me answer the question: am I making a bicycle and am I approaching the solution correctly?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question