Skip to content

Commit 547dac2

Browse files
committed
Adding new field to store image hash
1 parent 056f377 commit 547dac2

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

showcase/admin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
from .models import Showcase, ShowcaseSiteSettings
44

55

6-
admin.site.register(Showcase)
6+
class ShowcaseAdmin(admin.ModelAdmin):
7+
readonly_fields = ('hash',)
8+
9+
10+
admin.site.register(Showcase, ShowcaseAdmin)
711
admin.site.register(ShowcaseSiteSettings)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 3.1.8 on 2021-09-07 08:58
2+
3+
from django.db import migrations, models
4+
import uuid
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('showcase', '0002_showcasesitesettings'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='showcase',
16+
name='hash',
17+
field=models.UUIDField(default=uuid.uuid4, editable=False),
18+
),
19+
]

showcase/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import uuid
2+
13
from django.conf import settings
24
from django.db import models
35

@@ -30,6 +32,7 @@ class Showcase(models.Model):
3032
"the project. Img should ideally be 500x800px.")
3133
)
3234
is_public = models.BooleanField(default=True)
35+
hash = models.UUIDField(default=uuid.uuid4, editable=False)
3336

3437
def __str__(self):
3538
return self.display_name
@@ -55,6 +58,10 @@ def url(self):
5558
return (f'{settings.ACCOUNT_DEFAULT_HTTP_PROTOCOL}://'
5659
f'{settings.ALLOWED_HOSTS[0]}/showcase/{self.id}/')
5760

61+
@property
62+
def image_url(self):
63+
return f'{self.url}image/{self.hash.hex}/'
64+
5865

5966
class SingletonModel(models.Model):
6067
""" Singleton model for Showcases """

0 commit comments

Comments
 (0)