diff --git a/apps/payment/migrations/0025_giftcertificate_usergiftcertificate.py b/apps/payment/migrations/0025_giftcertificate_usergiftcertificate.py index d5ac1b08..3f9dcc34 100644 --- a/apps/payment/migrations/0025_giftcertificate_usergiftcertificate.py +++ b/apps/payment/migrations/0025_giftcertificate_usergiftcertificate.py @@ -24,7 +24,7 @@ class Migration(migrations.Migration): name='UserGiftCertificate', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('recipient', models.EmailField(max_length=254)), + ('recipient', models.EmailField(max_length=254, blank=True, null=True,)), ('bonuses_sent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='payment.UserBonus')), ('gift_certificate', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='payment.GiftCertificate')), ('payment', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='payment.Payment')), diff --git a/apps/payment/migrations/0027_auto_20181109_1402.py b/apps/payment/migrations/0027_auto_20181109_1402.py new file mode 100644 index 00000000..a228e06b --- /dev/null +++ b/apps/payment/migrations/0027_auto_20181109_1402.py @@ -0,0 +1,22 @@ +# Generated by Django 2.0.6 on 2018-11-09 14:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('payment', '0026_auto_20181101_1546'), + ] + + operations = [ + migrations.RemoveField( + model_name='usergiftcertificate', + name='recipient', + ), + migrations.AddField( + model_name='giftcertificate', + name='cover', + field=models.CharField(blank=True, default='', max_length=255), + ), + ] diff --git a/apps/payment/migrations/0028_add_gift_certificates.py b/apps/payment/migrations/0028_add_gift_certificates.py new file mode 100644 index 00000000..18c0ac4f --- /dev/null +++ b/apps/payment/migrations/0028_add_gift_certificates.py @@ -0,0 +1,21 @@ +# Generated by Django 2.0.6 on 2018-11-09 14:03 + +from django.db import migrations +from django.contrib.staticfiles.storage import staticfiles_storage + + +def add_gift_certificates(apps, schema_editor): + GiftCertificate = apps.get_model('payment', 'GiftCertificate') + for price in [1000, 2000, 3000, 5000, 10000]: + GiftCertificate.objects.create(price=price, + cover=staticfiles_storage.url('img/gift-certificates/%d.jpg' % price)) + +class Migration(migrations.Migration): + + dependencies = [ + ('payment', '0027_auto_20181109_1402'), + ] + + operations = [ + migrations.RunPython(add_gift_certificates), + ] diff --git a/apps/payment/models.py b/apps/payment/models.py index f7623038..413e8bf8 100644 --- a/apps/payment/models.py +++ b/apps/payment/models.py @@ -14,6 +14,7 @@ from django.core.validators import RegexValidator from django.utils.timezone import now from django.conf import settings +from apps.content.models import ImageObject from project.utils import weekdays_in_date_range from apps.course.models import Course @@ -314,6 +315,7 @@ class UserBonus(models.Model): class GiftCertificate(models.Model): price = models.DecimalField(max_digits=8, decimal_places=2, default=0) + cover = models.CharField(max_length=255, blank=True, default='') class Meta: ordering = ('price',) @@ -322,7 +324,6 @@ class GiftCertificate(models.Model): class UserGiftCertificate(models.Model): gift_certificate = models.ForeignKey(GiftCertificate, on_delete=models.CASCADE,) user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='gift_certificates') - recipient = models.EmailField() payment = models.ForeignKey(Payment, on_delete=models.SET_NULL, null=True) bonuses_sent = models.ForeignKey(UserBonus, on_delete=models.CASCADE, blank=True, null=True) diff --git a/apps/payment/templates/payment/gift_certificate_item.html b/apps/payment/templates/payment/gift_certificate_item.html index d642cf11..5f4a318e 100644 --- a/apps/payment/templates/payment/gift_certificate_item.html +++ b/apps/payment/templates/payment/gift_certificate_item.html @@ -3,7 +3,9 @@ {% load data_liked from data_liked %}