X-Git-Url: https://code.kerkeslager.com/?p=txt.house;a=blobdiff_plain;f=txt_house%2Fmodels.py;fp=txt_house%2Fmodels.py;h=2f57ca04dc020781222df18c1ed46ab1d05823d3;hp=0000000000000000000000000000000000000000;hb=3c5fb86f6a9a6c7fccb7b2975165ce6c29836c16;hpb=41e1451c39e5fbc1a22123e0492d1e549037d1e8 diff --git a/txt_house/models.py b/txt_house/models.py new file mode 100644 index 0000000..2f57ca0 --- /dev/null +++ b/txt_house/models.py @@ -0,0 +1,19 @@ +import base64 +import math + +from django.contrib import admin +from django.db import models +from django.urls import reverse + +class TextFile(models.Model): + text = models.TextField() + edit_key = models.CharField(max_length=43) + + def get_absolute_url(self): + pk = base64.urlsafe_b64encode( + self.pk.to_bytes(math.ceil(self.pk.bit_length() / 8), 'big'), + ).decode('utf-8') + + return reverse('text-file', kwargs={ 'pk': pk }) + +admin.site.register(TextFile)