我有一个包含所有必填字段的模型。 然后创建具有相同字段的视图。我可以成功保存表单中的值。 现在,我希望能够从表单上选择的network_size中计算出一个值,即network_range,并将该值与其他值一起保存
使用netbox代码,选择的network_size将计算IP地址范围。该地址已成功打印(调试)。我如何以表格形式保存network_range以及所有其他数据。例如,如果network_range给出此信息-172.16.3.224/28(我想将其保存在模型中)
org = account_form.cleaned_data['org']
acc_id = account_form.cleaned_data['acc_id']
account = account_form.cleaned_data['account']
email = account_form.cleaned_data['email']
network_size = account_form.cleaned_data['network_size']
budget_amount = account_form.cleaned_data['budget_amount']
budget_frequency = account_form.cleaned_data['budget_frequency']
service_level = account_form.cleaned_data['service_level']
account = account_form.save(commit=False)
netbox_conn = pynetbox.api("http://REDACTED","REDACTED")
get_parent_pref = netbox_conn.ipam.prefixes.get(30);print(get_parent_pref)
prefix = netbox_conn.ipam.prefixes.get(prefix=get_parent_pref);print("listpre"+str(prefix))
if network_size == "small":
network_range = prefix.available_prefixes.create({'prefix_length': 28})['prefix'];print(network_range)
elif network_size == "medium":
network_range = prefix.available_prefixes.create({'prefix_length': 25})['prefix'];print(network_range)
elif network_size == "large":
network_range = prefix.available_prefixes.create({'prefix_length': 24})['prefix'];print(network_range)
# account_temp.save()
network_range = ['network_range']
account.save()
return redirect(portal_account)```