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

Use COUPONS_COUPON_TYPES for the coupon form only #30

Open
wants to merge 1 commit 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
4 changes: 2 additions & 2 deletions coupons/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.utils.translation import ugettext_lazy as _
from django.views.generic.base import TemplateView

from .forms import CouponGenerationForm
from .forms import CouponGenerationForm, CouponAdminForm
from .models import Coupon, CouponUser, Campaign


Expand All @@ -19,6 +19,7 @@ def get_max_num(self, request, obj=None, **kwargs):


class CouponAdmin(admin.ModelAdmin):
form = CouponAdminForm
list_display = [
'created_at', 'code', 'type', 'value', 'user_count', 'user_limit', 'is_redeemed', 'valid_until', 'campaign'
]
Expand All @@ -36,7 +37,6 @@ def get_urls(self):
my_urls = [
url(r'generate-coupons', self.admin_site.admin_view(GenerateCouponsAdminView.as_view()),
name='generate_coupons'),

]
return my_urls + urls

Expand Down
8 changes: 8 additions & 0 deletions coupons/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
from .settings import COUPON_TYPES


class CouponAdminForm(forms.ModelForm):
type = forms.ChoiceField(label=_("Type"), choices=COUPON_TYPES)

class Meta:
fields = '__all__'
model = Coupon


class CouponGenerationForm(forms.Form):
quantity = forms.IntegerField(label=_("Quantity"))
value = forms.IntegerField(label=_("Value"))
Expand Down
20 changes: 20 additions & 0 deletions coupons/migrations/0008_auto_20180326_1414.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2018-03-26 13:14
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('coupons', '0007_auto_20151105_2328'),
]

operations = [
migrations.AlterField(
model_name='coupon',
name='type',
field=models.CharField(max_length=20, verbose_name='Type'),
),
]
2 changes: 1 addition & 1 deletion coupons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Coupon(models.Model):
code = models.CharField(
_("Code"), max_length=30, unique=True, blank=True,
help_text=_("Leaving this field empty will generate a random code."))
type = models.CharField(_("Type"), max_length=20, choices=COUPON_TYPES)
type = models.CharField(_("Type"), max_length=20)
user_limit = models.PositiveIntegerField(_("User limit"), default=1)
created_at = models.DateTimeField(_("Created at"), auto_now_add=True)
valid_until = models.DateTimeField(
Expand Down