Within the context of a serializer, see Serializers - Django REST framework (Django’s native serializers aren’t designed for those more intricate cases.)
But network_interface_data = azure.network_interface_azure_set.all() seem to work auto-magically - response from ChatGPT - but to convert it to a list - Im doing network_interface_data = list(azure.network_interface_azure_set.all()) which fails.
Ok, then there’s something else involved here. You either have a model manager, some other field or some other overridden function that is interferring with the normal process of this relationship. That is not the expected results of that statement in the common case.
network_interface_data = <QuerySet [<Network_interface_azure: Network_interface_azure object (1)>, <Network_interface_azure: Network_interface_azure object (2)>]>
type of network_interface_azure_set = <class 'django.db.models.query.QuerySet'>
Internal Server Error: /server/azure/715/update
Traceback (most recent call last):
File "D:\workspace\django\project1\env\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
File "D:\workspace\django\project1\env\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\workspace\django\project1\server\views.py", line 195, in azureUpdate
print("llist = ", list(azure.network_interface_azure_set.all()))
File "D:\workspace\django\project1\env\lib\site-packages\ms_identity_web\__init__.py", line 290, in assert_login
return f(*args, **kwargs)
File "D:\workspace\django\project1\server\views.py", line 47, in list
return render(request, 'inventory/aws_list.html')
File "D:\workspace\django\project1\env\lib\site-packages\django\shortcuts.py", line 24, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "D:\workspace\django\project1\env\lib\site-packages\django\template\loader.py", line 62, in render_to_string
return template.render(context, request)
File "D:\workspace\django\project1\env\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "D:\workspace\django\project1\env\lib\site-packages\django\template\base.py", line 173, in render
with context.bind_template(self):
File "C:\Users\AnjaneshLekshminaray\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 135, in __enter__
return next(self.gen)
File "D:\workspace\django\project1\env\lib\site-packages\django\template\context.py", line 254, in bind_template
updates.update(processor(self.request))
File "D:\workspace\django\project1\env\lib\site-packages\django\template\context_processors.py", line 41, in debug
if settings.DEBUG and request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS:
AttributeError: 'QuerySet' object has no attribute 'META'
[02/Jun/2023 06:15:49] "GET /server/azure/715/update HTTP/1.1" 500 116079
Well, looking at the traceback, the line actually causing that specific exception is:
The only reference to META here in that statement is the request.META.get(... clause in the if.
My initial reaction to seeing this would make me assume that somewhere in the call stack previous to this, the request obejct is being reassigned to a different value.
I’d start by closely examining the view containing this statement:
Am I sure that this is where the problem lies? No, far from it. But it’s where I would start.
(Note: This is another good example as to why people should always post the complete traceback when trying to diagnose errors.)
Thanks for making me notice that for some reason when I have this line inserted - print(list(azure.network_interface_azure_set.all())) - its trying to render the line return render(request, 'inventory/aws_list.html') which is in
def list(request):
print('list')
where as print(list(azure.network_interface_azure_set.all())) is inside
def azureUpdate(request, id):
# Code
print(list(azure.network_interface_azure_set.all()))
# Code
return render(request, 'inventory/azure/update.html', {
"ID": id,
"azure": azure,
# Other data
})
The view function obviously shouldn’t be named list !