1 from django.db import models
2 from django.urls import reverse
5 class Redirect(models.Model):
6 slug = models.SlugField(unique=True)
7 url = models.CharField(max_length=255)
8 counter = models.IntegerField(default=0)
9 created_at = models.DateTimeField(auto_now_add=True)
11 def get_absolute_url(self):
12 return reverse('redirect', args=[self.slug])
14 def update_counter(self):
15 type(self).objects.filter(pk=self.pk).update(counter=models.F('counter') + 1)