diff --git a/coupons/admin.py b/coupons/admin.py index f7f4392..712e0d2 100644 --- a/coupons/admin.py +++ b/coupons/admin.py @@ -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 @@ -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' ] @@ -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 diff --git a/coupons/forms.py b/coupons/forms.py index 2316c77..6d3b7c7 100644 --- a/coupons/forms.py +++ b/coupons/forms.py @@ -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")) diff --git a/coupons/migrations/0008_auto_20180326_1414.py b/coupons/migrations/0008_auto_20180326_1414.py new file mode 100644 index 0000000..f8d57f0 --- /dev/null +++ b/coupons/migrations/0008_auto_20180326_1414.py @@ -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'), + ), + ] diff --git a/coupons/models.py b/coupons/models.py index 2b69741..b952a87 100644 --- a/coupons/models.py +++ b/coupons/models.py @@ -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(