diff --git a/stats/models.py b/stats/models.py index bc7d827..1de6942 100644 --- a/stats/models.py +++ b/stats/models.py @@ -1,5 +1,6 @@ from django.contrib.gis.db import models from django.contrib.contenttypes.models import ContentType +from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.auth import get_user_model User = get_user_model() @@ -7,7 +8,14 @@ User = get_user_model() class StatsLog(models.Model): - model = models.ForeignKey(ContentType, on_delete=models.DO_NOTHING, null=True) + action_object_content_type = models.ForeignKey( + ContentType, blank=True, + null=True, + related_name='statslogs', + on_delete=models.CASCADE + ) + action_object_object_id = models.CharField(max_length=255, blank=True, null=True) + action_object = GenericForeignKey('action_object_content_type', 'action_object_object_id') user = models.ForeignKey(User, on_delete=models.DO_NOTHING, null=True) anonymous = models.BooleanField('Usuario no registrado', null=True) ip_address = models.GenericIPAddressField('IP usuario', null=True, blank=True)