pflaenz.li/pflaenzli/pflaenzli/templatetags/plz.py
Jannis Portmann b9fa20e4d6
All checks were successful
continuous-integration/drone/push Build is passing
Overhaul PLZ
2023-10-15 00:29:21 +02:00

15 lines
340 B
Python

from django import template
from pflaenzli.models import Plz
register = template.Library()
@register.filter
def get_plz(offer):
try:
return Plz.objects.get(plz=offer.zipcode)
except Plz.MultipleObjectsReturned:
return Plz.objects.filter(plz=offer.zipcode).first()
except Plz.DoesNotExist:
return None