Skip to content

Commit

Permalink
added a qr code image field for any future event (contains a URL to a…
Browse files Browse the repository at this point in the history
…n image that should be of the qr code's location)
  • Loading branch information
JasonLovesDoggo committed Jan 8, 2023
1 parent fa61c69 commit bf9b9a7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
5 changes: 2 additions & 3 deletions scavenger2022/core/admin.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions scavenger2022/core/migrations/0018_qrcode_image_url.py
Original file line number Diff line number Diff line change
@@ -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)",
),
),
]
14 changes: 14 additions & 0 deletions scavenger2022/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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('<img src="%s" />' % 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}"
Expand Down

0 comments on commit bf9b9a7

Please sign in to comment.