added new keyword management page

This commit is contained in:
smilerz
2021-02-17 07:09:19 -06:00
parent 505650518e
commit 6962b0e218
6 changed files with 208 additions and 16 deletions

View File

@ -1,4 +1,5 @@
import django_tables2 as tables
from django.db.models.functions import Lower
from django.utils.html import format_html
from django.utils.translation import gettext as _
from django_tables2.utils import A
@ -61,6 +62,28 @@ class KeywordTable(tables.Table):
fields = ('id', 'icon', 'name')
class ManageKeywordTable(tables.Table):
name = tables.LinkColumn('edit_keyword', args=[
A('id')])
class Meta:
model = Keyword
template_name = 'manage/keyword_table.html'
fields = ('id', 'name')
def render_name(self, value, record):
if record.icon != None:
return format_html("{} {}", record.icon, value)
else:
return value
def order_name(self, queryset, is_descending):
queryset = queryset.annotate(
name_lower=Lower('name')
).order_by(("-" if is_descending else "") + "name_lower")
return (queryset, True)
class IngredientTable(tables.Table):
id = tables.LinkColumn('edit_food', args=[A('id')])