From 14a41b01cf3c4b7a580df3d8ce70d8bbe3fc03ca Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 11 May 2017 04:07:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D1=81=D1=8F=20=D0=BE=D1=82=20ip=5Fpool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abonapp/models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/abonapp/models.py b/abonapp/models.py index 16bdd3e..01823b0 100644 --- a/abonapp/models.py +++ b/abonapp/models.py @@ -6,10 +6,10 @@ from django.db import models from django.core import validators from django.utils.translation import ugettext as _ from agent import Transmitter, AbonStruct, TariffStruct, NasFailedResult, NasNetworkError -from ip_pool.models import IpPoolItem from tariff_app.models import Tariff from accounts_app.models import UserProfile from .fields import MACAddressField +from mydefs import MyGenericIPAddressField class LogicError(Exception): @@ -207,7 +207,7 @@ class Abon(UserProfile): current_tariffs = models.ManyToManyField(Tariff, through=AbonTariff) group = models.ForeignKey(AbonGroup, models.SET_NULL, blank=True, null=True) ballance = models.FloatField(default=0.0) - ip_address = models.OneToOneField(IpPoolItem, on_delete=models.SET_NULL, null=True, blank=True) + ip_address = MyGenericIPAddressField(blank=True, null=True) description = models.TextField(null=True, blank=True) street = models.ForeignKey(AbonStreet, on_delete=models.SET_NULL, null=True, blank=True) house = models.CharField(max_length=12, null=True, blank=True) @@ -331,6 +331,13 @@ class Abon(UserProfile): agent_trf = TariffStruct() return AbonStruct(self.pk, user_ip, agent_trf, bool(self.is_active)) + def save(self, *args, **kwargs): + # проверяем не-ли у кого такого-же ip + if Abon.objects.filter(ip_address=self.ip_address).count() > 0: + self.is_bad_ip = True + raise LogicError(_('Ip address already exist')) + super(Abon, self).save(*args, **kwargs) + class AbonDevice(models.Model): abon = models.ForeignKey(Abon)