diff --git a/abonapp/migrations/0015_auto_20170410_1737.py b/abonapp/migrations/0015_auto_20170410_1737.py new file mode 100644 index 0000000..66a2f79 --- /dev/null +++ b/abonapp/migrations/0015_auto_20170410_1737.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2017-04-10 14:37 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('abonapp', '0014_auto_20170330_1452'), + ] + + operations = [ + migrations.AlterField( + model_name='abon', + name='opt82', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='abonapp.Opt82'), + ), + ] diff --git a/abonapp/models.py b/abonapp/models.py index 0ac7d09..1833abd 100644 --- a/abonapp/models.py +++ b/abonapp/models.py @@ -209,7 +209,7 @@ class Abon(UserProfile): street = models.ForeignKey(AbonStreet, on_delete=models.SET_NULL, null=True, blank=True) house = models.CharField(max_length=12, null=True, blank=True) extra_fields = models.ManyToManyField(ExtraFieldsModel, blank=True) - opt82 = models.ForeignKey(Opt82, null=True, blank=True) + opt82 = models.ForeignKey(Opt82, null=True, blank=True, on_delete=models.SET_NULL) _act_tar_cache = None @@ -422,6 +422,8 @@ def abon_post_save(sender, instance, **kwargs): def abon_del_signal(sender, instance, **kwargs): try: ab = instance.build_agent_struct() + if ab is None: + return True # подключаемся к NAS'у tm = Transmitter() # нашли абонента, и удаляем его на NAS diff --git a/abonapp/views.py b/abonapp/views.py index 3a44b82..1dad601 100644 --- a/abonapp/views.py +++ b/abonapp/views.py @@ -317,11 +317,10 @@ def opt82(request, gid, uid): act = request.GET.get('act') if act is not None and act == 'release': if abon.opt82 is not None: - #models.Opt82.objects.get(pk=abon.opt82.pk).delete() abon.opt82.delete() + abon.opt82 = None abon.save(update_fields=['opt82']) - except models.Abon.DoesNotExist: messages.error(request, _('User does not exist')) except models.Opt82.DoesNotExist: