Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing django2.0 #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 39 additions & 11 deletions coupons/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,61 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# Generated by Django 2.1.1 on 2019-03-11 21:50

from django.db import models, migrations
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Campaign',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True, verbose_name='Name')),
('description', models.TextField(blank=True, verbose_name='Description')),
],
options={
'verbose_name_plural': 'Campaigns',
'verbose_name': 'Campaign',
'ordering': ['name'],
},
),
migrations.CreateModel(
name='Coupon',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('value', models.IntegerField(help_text='Arbitrary coupon value', verbose_name='Value')),
('code', models.CharField(help_text='Leaving this field empty will generate a random code.', unique=True, max_length=30, verbose_name='Code', blank=True)),
('type', models.CharField(max_length=20, verbose_name='Type', choices=[(b'monetary', b'Money based coupon'), (b'percentage', b'Percentage discount'), (b'virtual_currency', b'Virtual currency')])),
('code', models.CharField(blank=True, help_text='Leaving this field empty will generate a random code.', max_length=30, unique=True, verbose_name='Code')),
('type', models.CharField(choices=[('monetary', 'Money based coupon'), ('percentage', 'Percentage discount'), ('virtual_currency', 'Virtual currency')], max_length=20, verbose_name='Type')),
('user_limit', models.PositiveIntegerField(default=1, verbose_name='User limit')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')),
('redeemed_at', models.DateTimeField(null=True, verbose_name='Redeemed at', blank=True)),
('user', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, help_text='You may specify a user you want to restrict this coupon to.', null=True, verbose_name='User')),
('valid_until', models.DateTimeField(blank=True, help_text='Leave empty for coupons that never expire', null=True, verbose_name='Valid until')),
('campaign', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='coupons', to='coupons.Campaign', verbose_name='Campaign')),
],
options={
'ordering': ['created_at'],
'verbose_name': 'Coupon',
'verbose_name_plural': 'Coupons',
'verbose_name': 'Coupon',
'ordering': ['created_at'],
},
bases=(models.Model,),
),
migrations.CreateModel(
name='CouponUser',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('redeemed_at', models.DateTimeField(blank=True, null=True, verbose_name='Redeemed at')),
('coupon', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='users', to='coupons.Coupon')),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='User')),
],
),
migrations.AlterUniqueTogether(
name='couponuser',
unique_together={('coupon', 'user')},
),
]
20 changes: 0 additions & 20 deletions coupons/migrations/0002_coupon_valid_until.py

This file was deleted.

39 changes: 0 additions & 39 deletions coupons/migrations/0003_auto_20150416_0617.py

This file was deleted.

43 changes: 0 additions & 43 deletions coupons/migrations/0004_auto_20151105_1456.py

This file was deleted.

27 changes: 0 additions & 27 deletions coupons/migrations/0005_auto_20151105_1502.py

This file was deleted.

22 changes: 0 additions & 22 deletions coupons/migrations/0006_auto_20151105_1509.py

This file was deleted.

18 changes: 0 additions & 18 deletions coupons/migrations/0007_auto_20151105_2328.py

This file was deleted.

7 changes: 4 additions & 3 deletions coupons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.conf import settings
from django.db import IntegrityError
from django.db import models
from django.db.models import CASCADE
from django.dispatch import Signal
from django.utils.encoding import python_2_unicode_compatible
from django.utils import timezone
Expand Down Expand Up @@ -76,7 +77,7 @@ class Coupon(models.Model):
valid_until = models.DateTimeField(
_("Valid until"), blank=True, null=True,
help_text=_("Leave empty for coupons that never expire"))
campaign = models.ForeignKey('Campaign', verbose_name=_("Campaign"), blank=True, null=True, related_name='coupons')
campaign = models.ForeignKey('Campaign', verbose_name=_("Campaign"), on_delete=CASCADE, blank=True, null=True, related_name='coupons')

objects = CouponManager()

Expand Down Expand Up @@ -149,8 +150,8 @@ def __str__(self):

@python_2_unicode_compatible
class CouponUser(models.Model):
coupon = models.ForeignKey(Coupon, related_name='users')
user = models.ForeignKey(user_model, verbose_name=_("User"), null=True, blank=True)
coupon = models.ForeignKey(Coupon, on_delete=CASCADE, related_name='users')
user = models.ForeignKey(user_model, verbose_name=_("User"), on_delete=CASCADE, null=True, blank=True)
redeemed_at = models.DateTimeField(_("Redeemed at"), blank=True, null=True)

class Meta:
Expand Down