A django-rest-framework application that provides many varieties of coupons
This project depends on:
djangorestframeworkdjango-filter
-
Install
drf-couponsvia pip:$ pip install drf-coupons -
Add
'rest_framework'toINSTALLED_APPSinsettings.py. -
Add
'coupons'toINSTALLED_APPSinsettings.py. -
Migrate database:
$ python manage.py migrate
Note: this package was not developed to be compatible side-by-side with django-coupons, as they serve very similar needs.
-
Specify permissions for interacting with coupon endpoints.
You can specify a list of groups that can perform specific actions against the coupons, such as restricting who can create or list coupons.
By default all endpoints are open except list.
retrievedoes not allow restriction because it doesn't generally need to support such permissions.patchis not supported as an endpoint and is therefore also not in theCOUPON_PERMISSIONS.COUPON_PERMISSIONS = { 'CREATE': ['groupa', 'groupb'], 'LIST': ['groupa'], 'DELETE': ['groupb'], 'UPDATE': ['groupb'], 'REDEEMED': ['groupc'], }You don't need to specify every endpoint in the list and can provide an empty list for an endpoint.
The groups specified for
REDEEMEDare used in bothGET /coupon/{pk}/redeemedandGET /redeemed.The groups specified for
DELETEare used in bothDELETE /coupon/{pk}andDELETE /redeemed/{pk}. -
Communicate with coupon endpoints.
You can place the urls into a subpath, however you like:
urlpatterns = [ # just adding here, but you can put into a subordinate path. url(r'^', include('coupons.urls')), ]As stated above, by default any user in the system can touch any of the below endpoints, except where specified in bold.
Endpoint Details GET /couponList all coupons in the system, only superuser or in group can see all. GET /coupon/{pk}Retrieve details about a coupon by database id POST /couponCreate a new coupon PUT /coupon/{pk}Update a coupon DELETE /coupon/{pk}Delete a coupon PUT /coupon/{pk}/redeemRedeem a coupon by database id GET /coupon/{pk}/redeemedList all times specified coupon was redeemed, superuser or group member can see all PATCH /coupon/{pk}Not supported GET /redeemedList all redeemed instances, filter-able only superuser or in group can do see all
GET /coupon supports querying by coupon code, and filter by user, bound, type or by ranges of discount via max_value, min_value
GET /redeemed supports filtering by user.
There are two objects provided:
-
Coupon- allows you to specify the properties of the coupon itself.Field Type Meaning codestringthe code for the coupon, case insensitive code_lstringautomatically set lowercase version of the coupon code typestringeither percentorvalue, how thevaluefield should be interpretedexpiresdatetimeoptional field to set when the coupon expires valuedecimalthe value for the coupon, such as 100or0.50boundbooleanif truethen the coupon can only be used by the specified user in theuserfielduserforeign keyset when bound to point to the user repeatintegerif 0the coupon can be used infinitely, otherwise it specifies how often any system user can use it -
ClaimedCoupon- allows you to track whenever a user redeems a coupon.Field Type Meaning redeemeddatetimeautomatically set when a coupon is redeemed couponforeign keyautomatically set to point at the coupon when redeemed userforeign keyautomatically set to point at the coupon when redeemed
It supports the following variations of coupons:
- Coupons can be a value, or a percentage.
- They can be bound to a specific user in the system.
- They can be single-use:
- per user (a pre-specified user can use it once),
case I - globally (any user in the system can use it, but only once)
case II
- per user (a pre-specified user can use it once),
- They can be infinite:
- per a specific user (a pre-specified user can use it repeatedly infinitely)
case III - infinite globally (any user can use it repeatedly infinitely)
case IV
- per a specific user (a pre-specified user can use it repeatedly infinitely)
- They can be used a specific number of times:
- per user (a pre-specified user can use it a specific number of times)
case V - globally (any user can use it a specific number of times)
case VI
- per user (a pre-specified user can use it a specific number of times)
- (They can be used by a specific list of users?) ... maybe later.
You create coupons in the system that are then claimed by users.
The unit-tests should automatically be run when you run python manage.py test and they are isolated.
If you'd like to contribute, please fork, and develop, branch from the development branch to and submit a pull request when ready.