Remove django-shorturls with my own implementation, since it's incompatible with Django 2 and unmaintained
This commit is contained in:
parent
27e0cb9a34
commit
098284a617
18 changed files with 252 additions and 184 deletions
16
lemonshort/short_url.py
Normal file
16
lemonshort/short_url.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
|
||||
from .convert import id_to_abc
|
||||
|
||||
prefixes = {}
|
||||
|
||||
|
||||
def short_url(entity):
|
||||
if not prefixes:
|
||||
for k, m in settings.SHORTEN_MODELS.items():
|
||||
prefixes[apps.get_model(m)] = k
|
||||
base = '/'
|
||||
if hasattr(settings, 'SHORT_BASE_URL'):
|
||||
base = settings.SHORT_BASE_URL
|
||||
return base + prefixes[type(entity)] + id_to_abc(entity.id)
|
||||
Loading…
Add table
Add a link
Reference in a new issue