mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-14 07:42:18 -06:00
16261 fix graphql lookup for MultiValueCharFilter fields (#16354)
* 16261 fix graphql lookup for MultiValueCharFilter fields * 16261 fix graphql lookup for MultiValueCharFilter fields * 16261 fixup test * 16261 fixup test * Omit redundant assignment --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
@@ -493,10 +493,18 @@ class APIViewTestCases:
|
||||
|
||||
def _build_filtered_query(self, name, **filters):
|
||||
"""
|
||||
Create a filtered query: i.e. ip_address_list(filters: {address: "1.1.1.1/24"}){.
|
||||
Create a filtered query: i.e. device_list(filters: {name: {i_contains: "akron"}}){.
|
||||
"""
|
||||
# TODO: This should be extended to support AND, OR multi-lookups
|
||||
if filters:
|
||||
filter_string = ', '.join(f'{k}: "{v}"' for k, v in filters.items())
|
||||
for field_name, params in filters.items():
|
||||
lookup = params['lookup']
|
||||
value = params['value']
|
||||
if lookup:
|
||||
query = f'{{{lookup}: "{value}"}}'
|
||||
filter_string = f'{field_name}: {query}'
|
||||
else:
|
||||
filter_string = f'{field_name}: "{value}"'
|
||||
filter_string = f'(filters: {{{filter_string}}})'
|
||||
else:
|
||||
filter_string = ''
|
||||
|
||||
Reference in New Issue
Block a user