Skip to content

Commit

Permalink
Added items page
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersSeverinsen committed Jul 26, 2024
1 parent 9a5cba6 commit a7ca159
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 470 deletions.
12 changes: 10 additions & 2 deletions items/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django import forms
from django.contrib import admin
from django.core.exceptions import FieldError
from django.utils.safestring import mark_safe

from items.models import BeerType, Brewery, InventoryEntry, InventorySnapshot, Item

Expand Down Expand Up @@ -33,9 +34,9 @@ def queryset(self, request, queryset):

@admin.register(Item)
class ItemAdmin(admin.ModelAdmin):
list_display = ("brewery", "name", "current_amount")
list_display = ("brewery", "name", "current_amount", "thumbnail")
search_fields = ("brewery__name", "name")
list_display_links = ("name",)
list_display_links = ("name", "thumbnail")
list_filter = (
AmountFilter,
"container",
Expand All @@ -50,6 +51,13 @@ class ItemAdmin(admin.ModelAdmin):
"type": BeerType,
}

def thumbnail(self, obj):
return (
mark_safe('<img src="%s" width="75px"/>' % obj.image.url)
if obj.image
else "<missing>"
)

def formfield_for_foreignkey(self, db_field, request, **kwargs):
"""Makes querysets for brewery and type fields ordered by name"""
return super().formfield_for_foreignkey(db_field, request, **kwargs)
Expand Down
42 changes: 42 additions & 0 deletions items/migrations/0002_auto_20240727_0123.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 3.2.4 on 2024-07-26 23:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("items", "0001_initial"),
]

operations = [
migrations.RemoveField(
model_name="item",
name="imageUrl",
),
migrations.AddField(
model_name="beertype",
name="name_dk",
field=models.CharField(blank=True, max_length=140, null=True),
),
migrations.AddField(
model_name="item",
name="container_dk",
field=models.CharField(blank=True, max_length=140),
),
migrations.AddField(
model_name="item",
name="image",
field=models.ImageField(blank=True, null=True, upload_to="items"),
),
migrations.AddField(
model_name="item",
name="name_dk",
field=models.CharField(blank=True, max_length=140, null=True),
),
migrations.AlterField(
model_name="item",
name="container",
field=models.CharField(blank=True, max_length=140),
),
]
16 changes: 6 additions & 10 deletions items/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
from django.db import models
from django.utils import timezone

CONTAINER = (
("DRAFT", "Fad"), # 0
("BOTTLE", "Flaske"), # 1
("SHOT", "Shot"), # 2
("FOOD", "Madvare"), # 3
("OTHER", "Andet"), # 4
)
from django.utils.translation import gettext_noop


class Item(models.Model):
Expand All @@ -18,14 +11,16 @@ class Item(models.Model):
"BeerType", on_delete=models.SET_NULL, null=True, blank=True
)
name = models.CharField(max_length=140)
name_dk = models.CharField(max_length=140, null=True, blank=True)
description = models.TextField(blank=True)
country = models.CharField(blank=True, max_length=140)
priceInDKK = models.DecimalField(max_digits=9 + 2, decimal_places=2)
abv = models.FloatField(null=True, blank=True)
container = models.CharField(choices=CONTAINER, blank=True, max_length=140)
container = models.CharField(blank=True, max_length=140)
container_dk = models.CharField(blank=True, max_length=140)
volumeInCentiliters = models.IntegerField(null=True, blank=True)
inStock = models.BooleanField(default=True)
imageUrl = models.CharField(max_length=255, blank=True)
image = models.ImageField(upload_to="items", blank=True, null=True)
barcode = models.CharField(max_length=255, unique=True, null=True, blank=True)

created = models.DateTimeField(auto_now_add=True)
Expand Down Expand Up @@ -59,6 +54,7 @@ def current_amount(self):

class BeerType(models.Model):
name = models.CharField(max_length=140)
name_dk = models.CharField(max_length=140, null=True, blank=True)
description = models.TextField(blank=True)
link = models.CharField(blank=True, max_length=255)

Expand Down
48 changes: 29 additions & 19 deletions items/templates/items.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

{% block content %}

{% load items_extras %}
{% load static %}

{% load i18n %}
<div class="row" id="sortiment-row">
<div class="col-sm-6">
<h2>
Sortiment
{% translate "Standardsortiment" %}
{% if items_data %}
<div id="sortiment-count">
({{ items_data | length }})
Expand All @@ -19,42 +18,53 @@ <h2>

{% if items_data %}
<div class="col-sm-6" id="sortiment-search">
<input type="text" id="itemsSearchInput" placeholder="Søg" autofocus>
<input type="text" id="itemsSearchInput" placeholder="{% translate "Søg" %}" autofocus>
</div>
{% endif %}
</div>

{% if show_all %}
<a href=".">Vis kun ting på lageret</a>
<a href=".">{% translate "Vis kun ting på lager" %}</a>
{% else %}
<a href="?show_all">Vis også ting ikke på lageret</a>
<a href="?show_all">{% translate "Vis også ting ikke på lager" %}</a>
{% endif %}


{% if items_data %}
<table class="table table-striped tablesorter" id="items">
<thead>
<tr>
<th>Bryghus</th>
<th>Navn</th>
<th class="hidden-xs">Beholder</th>
<th class="hidden-xs">Type</th>
<th>Pris</th>
<th>{% translate "Bryghus" %}<i class="fa fa-fw fa-sort"></i></span></th>
<th class="filter-select filter-exact">{% translate "Navn" %}<i class="fa fa-fw fa-sort"></i></th>
<th class="hidden-xs">{% translate "Type" %}<i class="fa fa-fw fa-sort"></i></th>
<th class="hidden-xs">{% translate "Container" %}<i class="fa fa-fw fa-sort"></i></th>
<th>{% translate "Pris" %}<i class="fa fa-fw fa-sort"></i></th>
<th class="hidden-xs">{% translate "Status" %}<i class="fa fa-fw fa-sort"></i></th>
<th class="hidden-xs">{% translate "Image" %}</i></th>
{% if user.is_staff %}
<th class="hidden-xs"></th>
{% endif %}
</tr>
</thead>
</thead>
<tbody>
{% get_current_language as LANGUAGE_CODE %}
{% for item in items_data %}
<tr>
<td>{{ item.brewery|default_if_none:"" }}</td>
<td>{{ item.name }}</td>
<td class="hidden-xs">{{ item.get_container_display }}</td>
<tr class="{% if not item.inStock %}danger{% endif %}">
<td>{% if item.brewery_url %}<a href="{{ item.brewery_url }}" target="_blank">{% endif %}{{ item.brewery|default_if_none:"" }}{% if item.brewery_url %}</a>{% endif %}</td>
<td>{% if LANGUAGE_CODE == 'da' %}{{ item.name_dk|default_if_none:item.name }}{% else %}{{ item.name|default_if_none:"" }}{% endif %}</td>
<td class="hidden-xs">{{ item.type|default_if_none:"" }}</td>
<td>{{ item.price|floatformat:-2 }}</td>
<td class="hidden-xs">{% if LANGUAGE_CODE == 'da' %}{{ item.container_dk|default_if_none:item.container }}{% else %}{{ item.container|default_if_none:"" }}{% endif %}</td>
<td>{{ item.price|floatformat:-2 }},-</td>
<td class="hidden-xs">{% if item.inStock %}{% translate "På lager" %}{% else %}{% translate "Ikke på lager" %}{% endif %}</td>
<td class="hidden-xs">
{% if item.image %}
<div class="board-image" style="background-image: url({{ item.image.url }});"></div>
{% else %}
<div class="board-image" style="background-image: url({% static 'images/logo.png' %});"></div>
{% endif %}
</td>
{% if user.is_staff %}
<td class="hidden-xs"><a href="/admin/items/item/{{ item.id }}">Edit</a></td>
<td class="hidden-xs"><a href="/admin/items/item/{{ item.id }}">{% translate "Edit" %}</a></td>
{% endif %}
</tr>
{% endfor %}
Expand All @@ -65,7 +75,7 @@ <h2>

{% else %}

<span>Sortimentet er desværre tomt &#9785;</span>
<span>{% translate "Sortimentet er desværre tomt" %} &#9785;</span>

{% endif %}
{% endblock %}
Loading

0 comments on commit a7ca159

Please sign in to comment.