Browse Source

Поправил связи ForeignKey чтоб не удалялись важные даннные по SQL CASCADE

devel
bashmak 9 years ago
parent
commit
c7ce6bb77e
  1. 22
      abonapp/migrations/0017_auto_20170416_1029.py
  2. 2
      abonapp/models.py
  3. 21
      accounts_app/migrations/0006_auto_20170416_1029.py
  4. 2
      accounts_app/models.py
  5. 10
      photo_app/models.py
  6. 27
      taskapp/migrations/0014_auto_20170416_1029.py
  7. 4
      taskapp/models.py

22
abonapp/migrations/0017_auto_20170416_1029.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2017-04-16 07:29
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('abonapp', '0016_auto_20170415_1311'),
]
operations = [
migrations.AlterField(
model_name='invoiceforpayment',
name='author',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL),
),
]

2
abonapp/models.py

@ -360,7 +360,7 @@ class InvoiceForPayment(models.Model):
comment = models.CharField(max_length=128)
date_create = models.DateTimeField(auto_now_add=True)
date_pay = models.DateTimeField(blank=True, null=True)
author = models.ForeignKey(UserProfile, related_name='+')
author = models.ForeignKey(UserProfile, related_name='+', on_delete=models.C, blank=True, null=True)
def __str__(self):
return "%s -> %.2f" % (self.abon.username, self.amount)

21
accounts_app/migrations/0006_auto_20170416_1029.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2017-04-16 07:29
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('accounts_app', '0005_auto_20170222_2224'),
]
operations = [
migrations.AlterField(
model_name='userprofile',
name='avatar',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='photo_app.Photo'),
),
]

2
accounts_app/models.py

@ -53,7 +53,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
#unique=True,
validators=[RegexValidator('^\+[7,8,9,3]\d{10,11}$')]
)
avatar = models.ForeignKey(Photo, null=True, blank=True)
avatar = models.ForeignKey(Photo, null=True, blank=True, on_delete=models.SET_NULL)
email = models.EmailField(default='admin@example.ru')
USERNAME_FIELD = 'username'

10
photo_app/models.py

@ -33,10 +33,14 @@ class Photo(models.Model):
im = Image.open(self.image.path)
im.thumbnail((759, 759), Image.ANTIALIAS)
hs = hashlib.md5(str(time.time())).hexdigest()
hs = hashlib.md5(str(time.time()).encode()).hexdigest()
ext = self.image.path.split('.')[1:][0]
fname = "%s/media/%s.%s" % (BASE_DIR, hs, ext)
path = "%s/media" % BASE_DIR
fname = "%s/%s.%s" % (path, hs, ext)
if not os.path.exists(path):
os.makedirs(path)
if not os.path.exists(path + '/min'):
os.makedirs(path + '/min')
im.save(fname)
os.remove(self.image.path)
self.image = "%s.%s" % (hs, ext)

27
taskapp/migrations/0014_auto_20170416_1029.py

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2017-04-16 07:29
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('taskapp', '0013_auto_20170413_1944'),
]
operations = [
migrations.AlterField(
model_name='task',
name='abon',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='abonapp.Abon'),
),
migrations.AlterField(
model_name='task',
name='author',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL),
),
]

4
taskapp/models.py

@ -61,7 +61,7 @@ def _delta_add_days():
class Task(models.Model):
descr = models.CharField(max_length=128, null=True, blank=True)
recipients = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='them_task')
author = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='+')
author = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='+', on_delete=models.SET_NULL, null=True, blank=True)
#device = models.ForeignKey(Device, related_name='dev')
priority = models.CharField(max_length=1, choices=TASK_PRIORITIES, default=TASK_PRIORITIES[2][0])
out_date = models.DateField(null=True, blank=True, default=_delta_add_days)
@ -69,7 +69,7 @@ class Task(models.Model):
state = models.CharField(max_length=1, choices=TASK_STATES, default=TASK_STATES[0][0])
attachment = models.ImageField(upload_to='task_attachments/%Y.%m.%d', blank=True, null=True)
mode = models.CharField(max_length=2, choices=TASK_TYPES, default=TASK_TYPES[0][0])
abon = models.ForeignKey(Abon, on_delete=models.SET_NULL, null=True, blank=True, related_name='+')
abon = models.ForeignKey(Abon, null=True, blank=True)
class Meta:
db_table = 'task'

Loading…
Cancel
Save