From ed735f85a69f8fc1c44eca2645778ad12b26c02c Mon Sep 17 00:00:00 2001 From: bashmak Date: Mon, 20 Feb 2017 17:17:44 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20=D0=B4=D0=B8=D0=BD=D0=B0?= =?UTF-8?q?=D0=BC=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D1=85=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abonapp/migrations/0010_auto_20170220_1630.py | 43 +++++++++++++++++++ abonapp/models.py | 29 ++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 abonapp/migrations/0010_auto_20170220_1630.py diff --git a/abonapp/migrations/0010_auto_20170220_1630.py b/abonapp/migrations/0010_auto_20170220_1630.py new file mode 100644 index 0000000..69718b8 --- /dev/null +++ b/abonapp/migrations/0010_auto_20170220_1630.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2017-02-20 13:30 +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('abonapp', '0009_abontariff_death_line'), + ] + + operations = [ + migrations.CreateModel( + name='ExtraFieldsModel', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('field_type', models.CharField(choices=[('int', 'Digital field'), ('str', 'Text field'), ('dbl', 'Floating field')], max_length=3)), + ('data', models.CharField(blank=True, max_length=64, null=True)), + ], + options={ + 'db_table': 'abon_extra_fields', + }, + ), + migrations.AlterModelOptions( + name='abon', + options={'permissions': (('can_buy_tariff', 'Покупка тарифа абоненту'), ('can_view_passport', 'Can view passport'))}, + ), + migrations.AlterModelOptions( + name='abontariff', + options={'ordering': ('tariff_priority',), 'permissions': (('can_complete_service', 'Снятие со счёта средств'), ('can_activate_service', 'Активация услуги абонента'))}, + ), + migrations.AlterField( + model_name='abon', + name='ballance', + field=models.FloatField(default=0.0), + ), + migrations.AddField( + model_name='extrafieldsmodel', + name='account', + field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='abonapp.Abon'), + ), + ] diff --git a/abonapp/models.py b/abonapp/models.py index f285ae3..eb310a5 100644 --- a/abonapp/models.py +++ b/abonapp/models.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from django.utils import timezone from django.db import models -from django.core.validators import DecimalValidator +from django.core import validators from django.utils.translation import ugettext as _ from agent import Transmitter, AbonStruct, TariffStruct, NasFailedResult from ip_pool.models import IpPoolItem @@ -159,7 +159,7 @@ class AbonStreet(models.Model): 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, validators=[DecimalValidator]) + ballance = models.FloatField(default=0.0) ip_address = models.OneToOneField(IpPoolItem, on_delete=models.SET_NULL, null=True, blank=True) description = models.TextField(null=True, blank=True) street = models.ForeignKey(AbonStreet, on_delete=models.SET_NULL, null=True, blank=True) @@ -185,6 +185,7 @@ class Abon(UserProfile): db_table = 'abonent' permissions = ( ('can_buy_tariff', _('Buy service perm')), + ('can_view_passport', _('Can view passport')) ) # Платим за что-то @@ -346,6 +347,30 @@ class AbonRawPassword(models.Model): db_table = 'abon_raw_password' +class ExtraFieldsModel(models.Model): + DYNAMIC_FIELD_TYPES = ( + ('int', _('Digital field')), + ('str', _('Text field')), + ('dbl', _('Floating field')) + ) + + field_type = models.CharField(max_length=3, choices=DYNAMIC_FIELD_TYPES) + account = models.ForeignKey(Abon, on_delete=models.DO_NOTHING) + data = models.CharField(max_length=64, null=True, blank=True) + + def clean(self): + val = None + if self.field_type == 'int': + val = validators.integer_validator + elif self.field_type == 'dbl': + val = validators.DecimalValidator(9, 6) + if val: + self.validators.append(val) + + class Meta: + db_table = 'abon_extra_fields' + + def abon_post_save(sender, instance, **kwargs): try: tm = Transmitter()