fix: increase max_length of SubnetField for IPv6 subnets

Increased the max_length attribute of SubnetField from 43 to 45 to properly accommodate the longest possible IPv6 subnet representation. This adjustment ensures that all valid IPv6 subnets can be correctly stored, preventing potential data truncation issues.
This commit is contained in:
Kumi 2024-07-12 14:17:14 +02:00
parent eb50798b14
commit 245f50d0fd
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -1,11 +1,12 @@
from django.db import models
import ipaddress
class SubnetField(models.CharField):
description = "A field to store IPv4 or IPv6 subnets"
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 43 # Maximum length for IPv6 with subnet
kwargs["max_length"] = 45 # Maximum length for IPv6 with subnet
super().__init__(*args, **kwargs)
def from_db_value(self, value, expression, connection):