from django.contrib.auth import get_user_model from django.db import models from .utils import choices_length User = get_user_model() LOG_LEVELS = ( ("info", "INFO"), ("warning", "WARNING"), ("error", "ERROR"), ) class Event(models.Model): message = models.TextField(default="") level = models.CharField(choices=LOG_LEVELS, max_length=choices_length(LOG_LEVELS)) timestamp = models.DateTimeField(auto_now_add=True) data = models.JSONField(default=dict) user = models.ForeignKey( User, related_name="events", on_delete=models.SET_NULL, null=True ) class Meta: ordering = ["-timestamp"]