Merge pull request #2041 from SchrodingersGat/metadata-fixes

Fix OPTIONS request lookup time
This commit is contained in:
Oliver 2021-09-08 12:52:00 +10:00 committed by GitHub
commit ba787a0485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,10 +98,12 @@ class InvenTreeMetadata(SimpleMetadata):
serializer_info = super().get_serializer_info(serializer)
try:
ModelClass = serializer.Meta.model
model_class = None
model_fields = model_meta.get_field_info(ModelClass)
try:
model_class = serializer.Meta.model
model_fields = model_meta.get_field_info(model_class)
# Iterate through simple fields
for name, field in model_fields.fields.items():
@ -146,11 +148,23 @@ class InvenTreeMetadata(SimpleMetadata):
if hasattr(serializer, 'instance'):
instance = serializer.instance
if instance is None:
try:
instance = self.view.get_object()
except:
pass
if instance is None and model_class is not None:
# Attempt to find the instance based on kwargs lookup
kwargs = getattr(self.view, 'kwargs', None)
if kwargs:
pk = None
for field in ['pk', 'id', 'PK', 'ID']:
if field in kwargs:
pk = kwargs[field]
break
if pk is not None:
try:
instance = model_class.objects.get(pk=pk)
except (ValueError, model_class.DoesNotExist):
pass
if instance is not None:
"""