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

Clean up limit_to for ForeignKeys referencing ContentType

This commit is contained in:
Jeremy Stretch
2019-04-17 13:36:05 -04:00
parent eb86053a53
commit cd3924520d
4 changed files with 81 additions and 25 deletions

View File

@@ -60,6 +60,17 @@ def dynamic_import(name):
return mod
def model_names_to_filter_dict(names):
"""
Accept a list of content types in the format ['<app>.<model>', '<app>.<model>', ...] and return a dictionary
suitable for QuerySet filtering.
"""
# TODO: This should match on the app_label as well as the model name to avoid potential duplicate names
return {
'model__in': [model.split('.')[1] for model in names],
}
def serialize_object(obj, extra=None):
"""
Return a generic JSON representation of an object using Django's built-in serializer. (This is used for things like