django-coupons
A reuseable Django application for coupon gereration and handling
Setup instructions
-
Install
django-coupons
via pip:$ pip install django-coupons
-
Add
'coupons'
toINSTALLED_APPS
insettings.py
. -
Migrate database:
$ python manage.py migrate
Working with coupons
To manage coupons, use the administration interface.
Manualy adding coupons
To manually add coupons for discounts:
- Click Add coupon
- Enter the coupon properties:
Property | Description |
---|---|
Code | Code used by the customer to apply the coupon. A combination of letters, digits and other characters that make up the code of the coupon. The code serves as a unique identifier for the coupon. Leave the field empty to generate random code. |
Value | Amount/Percent, depending on discount type you choose, that will be taken off the subtotal of any invoices. Entered without a currency unit or a percent sign. |
Type |
|
User limit | Maximum number of times this coupon can be redeemed, in total, across all users, before it is no longer valid. The system counts redemptions once for each purchase, not for each product affected by the related discount. Set zero to allow unlimited use of the coupon code. |
Valid until | Date after which the coupon can no longer be redeemed. Leave empty for coupons that never expire. |
Duration | The Duration deals with the recurring functionality of coupons. This specifies how long a coupon can be applied to a subscription after being added. There are 3 types of durations:
|
Duration in months | If duration is repeating, the number of months the coupon applies. |
Coupon users | Bound coupon to a specific user(s) |
- Click Save
Supported use cases of coupons
This application supports different kind of coupons in the way how they can be redeemed. The difference is defined by the number of possible redeems and if they are bound to a specific user (may even be a list of users) or not.
1) single time (default), coupon can be used one time without being bound to an user.
2) user limited, coupon can be used one time but only by a specific user.
3) limit number, coupon can be used a limited number of times, by any user once.
4) users list, coupon can be used by a defined list of users, each once.
5) unlimited, coupon can be used unlimited times, but only once by the same user.
Generating coupons
To have the system generate multiple coupons at once:
- Click Generate coupons
- Specify the properties of the coupon code generator:
Property | Description |
---|---|
Quantity | Specify how many coupon codes the system generates after you click Generate. |
Prefix | The system generates random coupon codes. The coupon code prefix allows you to enter a prefix to be shared by all codes generated in the current batch operation. If you leave the field empty, the system generates coupon codes without a shared prefix. |
- Click Generate
The system creates the specified number of new coupon codes, optionally with the specified code prefix.
Generating random coupon code
If coupon code is not defined it will be generated randomly by the system. Still some rules will be used that can be redefined in settings:
- COUPONS_CODE_LENGTH - Length of coupon code, 15 by default
- COUPONS_CODE_CHARS - Characters used to generate code, combination of ascii letters and digits by default
- COUPONS_SEGMENTED_CODES - Whether code should be splited into segments, False by default
- COUPONS_SEGMENT_LENGTH - Length of code segment, 4 by default
- COUPONS_SEGMENT_SEPARATOR - Separator used to separate code segments, '-' by default