From a6569cb8ff5aef198cca0f2bac00f5e5cce65308 Mon Sep 17 00:00:00 2001 From: Will Stott Date: Wed, 17 Jul 2019 13:51:53 +0100 Subject: [PATCH] Use Django's standard field rendering. Create filter for custom attrs. --- core/templatetags/bootstrap_field.py | 18 +++++++++--------- pinry/templates/includes/field.html | 4 +++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core/templatetags/bootstrap_field.py b/core/templatetags/bootstrap_field.py index 84d8f00..7216aff 100644 --- a/core/templatetags/bootstrap_field.py +++ b/core/templatetags/bootstrap_field.py @@ -1,10 +1,10 @@ -from django.template import loader, Context, Library - - +from django.template import Library + register = Library() - - -@register.simple_tag -def bootstrap_field(field): - template = loader.get_template('core/templatetags/bootstrap_field.html') - return template.render(Context({'field': field})) + +@register.filter(name='bootstrap_field') +def bootstrap_field(field, class_attr): + return field.as_widget(attrs={ + 'placeholder': field.label, + 'class': class_attr + }) diff --git a/pinry/templates/includes/field.html b/pinry/templates/includes/field.html index 50b1d9b..9d39b41 100644 --- a/pinry/templates/includes/field.html +++ b/pinry/templates/includes/field.html @@ -1,5 +1,7 @@ +{% load bootstrap_field %} +
- + {{ field|bootstrap_field:"form-control input-lg" }} {% if field.errors %} {% if field.errors %}