from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.db import models from core.http.models import User class History(models.Model): content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) object_id = models.PositiveIntegerField() content_object = GenericForeignKey("content_type", "object_id") action = models.CharField(max_length=255) user_id = models.ForeignKey( to=User, on_delete=models.CASCADE, related_name="history" ) avatar = models.ImageField( upload_to="history_avatars/", null=True, blank=True ) timestamp = models.DateTimeField(auto_now_add=True) created_by = models.CharField(max_length=255, null=True, blank=True) created_who = models.CharField(max_length=255, null=True, blank=True) comment = models.CharField(max_length=255, null=True, blank=True) reason = models.CharField(max_length=255, null=True, blank=True) class Meta: ordering = ["-timestamp"]