Better management of manually-set members.
[wolnelektury.git] / src / redirects / models.py
1 from django.db import models
2 from django.urls import reverse
3
4
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)
10
11     def get_absolute_url(self):
12         return reverse('redirect', args=[self.slug])
13
14     def update_counter(self):
15         type(self).objects.filter(pk=self.pk).update(counter=models.F('counter') + 1)
16