mpri-webdam/histories/models.py
2018-02-19 13:59:29 +01:00

38 lines
1.1 KiB
Python

""" Models for the history. This history should be able to generate history
entries, which looks like human-based browsing, according to a dedicated user
interests, keywords...
"""
from django.db import models
from profiles.models import BrowserFingerprint
class HistoryEntry(models.Model):
""" A history entry, aka a url, and a timestamp.
"""
search = models.CharField(max_length=255)
timestamp = models.DateTimeField()
history = models.ForeignKey(
'History',
on_delete=models.CASCADE
)
def __str__(self):
return "{} : {}".format(self.timestamp, self.search)
class History(models.Model):
""" A history for a user, containing some web connections (http, https).
Each history is timed, in a human-behaviour manner. """
start_ts = models.DateTimeField()
played = models.BooleanField(default=False)
user_agent = models.ForeignKey(
BrowserFingerprint,
on_delete=models.CASCADE
)
def __str__(self):
history_set = self.history_set.order_by('timestamp')
header = "[History]:\n"
return header + "\n".join(history_set)