add absolute url to file model

This commit is contained in:
Jake Howard 2016-09-06 14:05:03 +01:00
parent 1dd4ac8088
commit 391da3fd27
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -1,9 +1,9 @@
from django.db import models from django.db import models
import os
import uuid import uuid
from admin_resumable.fields import ModelAdminResumableFileField from admin_resumable.fields import ModelAdminResumableFileField
from shortuuidfield import ShortUUIDField from shortuuidfield import ShortUUIDField
from datetime import timedelta from datetime import timedelta
from django.core.urlresolvers import reverse
class SharedFile(models.Model): class SharedFile(models.Model):
@ -14,9 +14,15 @@ class SharedFile(models.Model):
hotlink = models.BooleanField(default=False) hotlink = models.BooleanField(default=False)
published = models.BooleanField(default=True) published = models.BooleanField(default=True)
def __str__(self):
return self.get_original_filename()
def get_original_filename(self): def get_original_filename(self):
return "_".join(self.file.name.split('_')[1:]) return "_".join(self.file.name.split('_')[1:])
def get_absolute_url(self):
return reverse('files:file', args=(self.short_id,))
class FileToken(models.Model): class FileToken(models.Model):
valid_time = timedelta(minutes=5) valid_time = timedelta(minutes=5)