feat(models): add validators for VPN port range

Added MinValueValidator and MaxValueValidator for the port field in the VPN model to ensure values are between 10000 and 40000. This change enforces port number constraints directly in the model, preventing invalid entries and improving data integrity.
This commit is contained in:
Kumi 2024-07-12 08:40:41 +02:00
parent e1bf6b9901
commit c7c05f2677
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -1,5 +1,6 @@
from django.db import models from django.db import models
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.core.validators import MinValueValidator, MaxValueValidator
from uuid import uuid4 from uuid import uuid4
@ -16,7 +17,10 @@ class VPN(models.Model):
owner = models.ForeignKey(get_user_model(), models.CASCADE) owner = models.ForeignKey(get_user_model(), models.CASCADE)
name = models.CharField(max_length=128) name = models.CharField(max_length=128)
port = models.IntegerField( port = models.IntegerField(
unique=True, min_value=10000, max_value=40000, null=True, blank=True unique=True,
null=True,
blank=True,
validators=[MinValueValidator(10000), MaxValueValidator(40000)],
) )
private_key = EncryptedCharField(max_length=128, null=True, blank=True) private_key = EncryptedCharField(max_length=128, null=True, blank=True)
public_key = models.CharField(max_length=128, null=True, blank=True) public_key = models.CharField(max_length=128, null=True, blank=True)