tdg_rocks/shorturls/models.py

19 lines
505 B
Python

from django.db import models
from .utils import create_short_url
class ShortURL(models.Model):
created = models.DateTimeField(auto_now_add=True)
followed = models.PositiveIntegerField(default=0)
long_url = models.TextField()
short_url = models.CharField(max_length=20, unique=True, blank=True)
def save(self, *args, **kwargs):
if not self.short_url:
self.short_url = create_short_url(self)
super().save()
class Meta:
ordering = ["created"]