Skip to content

Commit

Permalink
fixed handling of devices
Browse files Browse the repository at this point in the history
when the protocol attribute of a device is None the device admin
interface has failed fails
  • Loading branch information
trombastic authored and clavay committed May 17, 2023
1 parent f3d889e commit d6f51e6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pyscada/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs):
# For new device, show all the protocols from the installed apps in settings.py
# For existing device, show only the selected protocol to avoid changing
if db_field.name == "protocol":
if 'object_id' in request.resolver_match.kwargs and Device.objects.get(id=request.resolver_match.kwargs['object_id']) is not None:
if 'object_id' in request.resolver_match.kwargs \
and Device.objects.get(id=request.resolver_match.kwargs['object_id']) is not None \
and Device.objects.get(id=request.resolver_match.kwargs['object_id']).protocol:
kwargs["queryset"] = DeviceProtocol.objects.filter(protocol__in=[Device.objects.get(id=request.resolver_match.kwargs['object_id']).protocol.protocol,])
else:
kwargs["queryset"] = DeviceProtocol.objects.filter(protocol__in=self.protocol_list)
Expand Down

0 comments on commit d6f51e6

Please sign in to comment.