From bf9b9a7af8e33213c2892ac9f347dd251cbc5891 Mon Sep 17 00:00:00 2001 From: Jason Date: Sat, 7 Jan 2023 22:36:27 -0500 Subject: [PATCH] added a qr code image field for any future event (contains a URL to an image that should be of the qr code's location) --- scavenger2022/core/admin.py | 5 ++--- .../core/migrations/0018_qrcode_image_url.py | 21 +++++++++++++++++++ scavenger2022/core/models.py | 14 +++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 scavenger2022/core/migrations/0018_qrcode_image_url.py diff --git a/scavenger2022/core/admin.py b/scavenger2022/core/admin.py index 9fcc7e3..0ceebec 100644 --- a/scavenger2022/core/admin.py +++ b/scavenger2022/core/admin.py @@ -1,6 +1,5 @@ from django.contrib import admin from django.contrib.auth.admin import UserAdmin as UserAdmin_ -from django.utils.html import format_html from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _l from django.urls import reverse @@ -59,8 +58,8 @@ def path(self, team): class QrCodeAdmin(admin.ModelAdmin): - fields = ["short", "location", "notes", "key"] - readonly_fields = ["url", "key"] + fields = ["short", "location", "notes", "key", "image_tag", "image_url"] + readonly_fields = ["url", "key", "image_tag"] list_display = ["location", "url"] inlines = [HintsInLine] form = QrCodeAdminForm diff --git a/scavenger2022/core/migrations/0018_qrcode_image_url.py b/scavenger2022/core/migrations/0018_qrcode_image_url.py new file mode 100644 index 0000000..74f68d4 --- /dev/null +++ b/scavenger2022/core/migrations/0018_qrcode_image_url.py @@ -0,0 +1,21 @@ +# Generated by Django 4.1.4 on 2023-01-08 03:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0017_alter_user_team"), + ] + + operations = [ + migrations.AddField( + model_name="qrcode", + name="image_url", + field=models.URLField( + blank=True, + help_text="A URL to an image of where the QR code is located (try imgur)", + ), + ), + ] diff --git a/scavenger2022/core/models.py b/scavenger2022/core/models.py index 7ddd965..1539b51 100644 --- a/scavenger2022/core/models.py +++ b/scavenger2022/core/models.py @@ -6,6 +6,7 @@ from django.conf import settings from django.contrib.auth.models import AbstractUser from django.db import models +from django.utils.html import format_html def generate_invite_code(): @@ -44,6 +45,19 @@ class QrCode(models.Model): ) notes = models.TextField(help_text="Internal notes", blank=True) key = models.CharField(max_length=64, unique=True, default=generate_hint_key) + image_url = models.URLField( + help_text="A URL to an image of where the QR code is located (try imgur)", + blank=True, + ) + + def image_tag(self): + from django.utils.html import escape + + if self.image_url: + return format_html('' % escape(self.image_url)) + + image_tag.short_description = "QR Image" + image_tag.allow_tags = True def __str__(self): return f"{self.id} {self.short or self.location}"