From c7c05f26775766b28e20bb7562e21caf8b72fbf8 Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 12 Jul 2024 08:40:41 +0200 Subject: [PATCH] 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. --- coldbrew/vpn/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/coldbrew/vpn/models.py b/coldbrew/vpn/models.py index f2d1ab8..adcbabe 100644 --- a/coldbrew/vpn/models.py +++ b/coldbrew/vpn/models.py @@ -1,5 +1,6 @@ from django.db import models from django.contrib.auth import get_user_model +from django.core.validators import MinValueValidator, MaxValueValidator from uuid import uuid4 @@ -16,7 +17,10 @@ class VPN(models.Model): owner = models.ForeignKey(get_user_model(), models.CASCADE) name = models.CharField(max_length=128) 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) public_key = models.CharField(max_length=128, null=True, blank=True)