我有一个IPv4Manage模型:
class IPv4Manage(models.Model):
...
vlanedipv4network = models.ForeignKey(
to=VlanedIPv4Network, related_name="ipv4s", on_delete=models.DO_NOTHING, null=True)
当我更新ipv4实例时:
vlaned_ipv4_network = VlanedIPv4Network.objects.create(
network_ip = ip_network_divided_obj.network_address.exploded,
prefix = ip_network_divided_obj.prefixlen,
gateway_ip = gateway_ip.exploded,
broadcast_ip = ip_network_divided_obj.broadcast_address.exploded,
ipv4networkmanage = vlanable_ipv4network.ipv4networkmanage,
)
...
ipv4 = IPv4Manage.objects.get(ip=ip)
ipv4.netmask = bits_to_mask(ip_network_divided_obj.prefixlen)
if ipv4.ip == gateway_ip:
ipv4.is_gateway = True
else:
ipv4.is_gateway = False
ipv4.ip_status = IPV4_STATUS.已Vlan化未配置服务器
ipv4.vlanedipv4network = vlaned_ipv4_network, # there comes the issue
ipv4.save()
Cannot assign "(<VlanedIPv4Network: 103.35.203.6/31>,)": "IPv4Manage.vlanedipv4network" must be a "VlanedIPv4Network" instance.
但我的vlaned_ipv4_network
确实是VlanedIPv4Network
个实例。
答案 0 :(得分:1)
在该行的末尾有一个额外的逗号。