Just wondering, I have the following model schema:
class Location(models.Model):
SERVICE_CHOICES = (
('bus_station', 'Bus Station'),
('cafe', 'Café'),
('cinema', 'Cinema'),
('gardens', 'Public Gardens'),
('library', 'Library'),
('public_services', 'Public Services'),
('railway_station', 'Railway Station'),
('restaurant', 'Restaurant'),
('school', 'School'),
('shop', 'Shop'),
('supermarket', 'Supermarket'),
('tourist_attractions', 'Tourist Attractions'),
('transit_station', 'Transit Station'),
('walks', 'Walks'),
('woodland', 'Woodland'),
)
title = models.CharField("Title", max_length=60, default='')
description = models.TextField("Description")
service_type = models.CharField("Service Type", max_length=80, choices=SERVICE_CHOICES, default='public_service')
I'm just wondering how I would loop over the SERVICE_CHOICES tuple list on the frontend template?
{% for service_choice in location.SERVICE_CHOICES %}
?
On below suggestion, I have tried this in the view:
service_types = []
fields = Location._meta.fields()
for field in fields:
if field.choices:
service_types.append(field.choices)