1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #3190: Fix custom field rendering for Jinja2 export templates

This commit is contained in:
Jeremy Stretch
2019-05-16 19:45:36 -04:00
parent 62d497dd0b
commit 2f32488c25
4 changed files with 25 additions and 21 deletions

View File

@@ -1,6 +1,24 @@
from collections import OrderedDict
from django.db.models import Q, QuerySet
class CustomFieldQueryset:
"""
Annotate custom fields on objects within a QuerySet.
"""
def __init__(self, queryset, custom_fields):
self.queryset = queryset
self.model = queryset.model
self.custom_fields = custom_fields
def __iter__(self):
for obj in self.queryset:
values_dict = {cfv.field_id: cfv.value for cfv in obj.custom_field_values.all()}
obj.custom_fields = OrderedDict([(field, values_dict.get(field.pk)) for field in self.custom_fields])
yield obj
class ConfigContextQuerySet(QuerySet):
def get_for_object(self, obj):