Package: django-affiliate
Affiliate system for djangoAffiliate system to reward partners with their visitors payments.
Contains abstract models with basic functionality, so it is easy to
subclass them and add your custom logic and relations.Note: version 0.2.0 is backwards incompatible with previous
versions.ExampleVisitor goes to site with affiliate code:http://site.com/?aid=12345This code is saved in his cookies (also another way is supported: keep
aid=12345 at every url). Now each request object has propertyrequest.affiliate, so you can access to affiliate, that attract
current visitor, and therefore reward him at needed event.Propertyrequest.affiliateis lazy. To check, that affiliate exist,
do this:if request.affiliate.exists():
    # optionally check, that he is active:
    if request.affiliate.is_active:
        # request comes from affiliate with code
        # affiliate.aidYou can find example project in this repository.Used by projectsbuilds.iowirelayer.netsmmplanner.comRequirementspython (2.7, 3.4, 3.5)django (1.6, 1.7, 1.8, 1.9)Quick startInstall this package to your python distributionpip install django-affiliateAdd ‘affiliate’ to INSTALLED_APP:INSTALLED_APPS = [
    # ...
    'affiliate',
]Add ‘affiliate.middleware.AffiliateMiddleware’ to
MIDDLEWARE_CLASSES:MIDDLEWARE_CLASSES = (
    # ...
    'affiliate.middleware.AffiliateMiddleware',
)Define your custom affiliate model (similar to custom user model):# our_app/models.py
from django.db import models
from affiliate.models import AbstractAffiliate


class Affiliate(AbstractAffiliate):
    pass  # or add some your custom fields here

# settngs.py
AFFILIATE_AFFILIATE_MODEL = 'our_app.Affiliate'Create tables# django <= 1.6
python manage.py syncdb

# django <= 1.6 & south
python manage.py schemamigration our_app --auto
python manage.py migrate our_app

# django >= 1.7
python manage.py makemigrations our_app
python manage.py migrate our_appFinally, reward affiliatefrom django.views.generic import FormView
from affiliate.tools import get_affiliate_model

Affiliate = get_affiliate_model()

class SomeView(FormView):
    # ...

    def form_valid(self.form):
        product = self.get_product()
        if self.request.affiliate.exists() and self.request.affiliate.is_active:
            # reward affiliate here, your custom logic is here
            Transaction.objects.create(
                user=self.affiliate.user,
                amount=Affiliate.calc_affiliate_reward(product.price))
            return super(SomeView, self).form_valid(form)OptionalTo always keep the aid GET parameter (maybe you don’t trust the cookies
or you want to reward affiliate only if his visitor make payment at
current link access, and not tomorrow)Load ‘affiliate_urls’ tags:{% load affiliate_urls %}Use ‘url_aff’ instead of ‘url’ template tag:<a href="{% url_aff 'home' %}">Home</a>ConfigurationDefine in settings.pyAFFILIATE_AFFILIATE_MODEL - the model to use to represent an
Affiliate, similar toAUTH_USER_MODEL.
Mandatory, must be explicitly defined.AFFILIATE_PARAM_NAME - name of affiliate GET parameter in url.
Default'aid'.AFFILIATE_REWARD_AMOUNT - default affiliate reward amount. Can be
set as string ('5.55') or as int (10). Default10.AFFILIATE_REWARD_PERCENTAGE - if True,AFFILIATE_REWARD_AMOUNTis treated as percentage. Otherwise as exact amount of money. DefaultTrue.AFFILIATE_SAVE_IN_SESSION - save affiliate id in session or not.
DefaultTrue.AFFILIATE_SESSION_AGE - how long keep affiliate id in session, in
seconds. Default5 * 24 * 60 * 60seconds (5 days).AFFILIATE_DEFAULT_LINK - default link, that will be used byAffiliate.build_absolute_affiliate_uriand.build_affiliate_url. Default'/'.AFFILIATE_REMOVE_PARAM_AND_REDIRECT - if True, remove affiliate
param from url and redirect to same url (affiliate data will be saved
in session). DefaultFalse.django-affiliate release notesv0.4.0 (2016-05-24)django 1.9 supportpython 3.5 supportIssues: #12v0.3.3 (2016-04-10)Don’t raise exception in case of bad aid code typeIssues: #10v0.3.2 (2016-11-29)if AFFILIATE_REMOVE_PARAM_AND_REDIRECT is True, perform redirect
only in case of GET request methodv0.3.1 (2015-11-29)add setting AFFILIATE_REMOVE_PARAM_AND_REDIRECT, that allows to
remove affiliate param from url and redirectv0.2.1 (2015-10-29)add translations to pypiv0.2.0 (2015-10-29)only affiliate model defined by packagerequest now have lazyaffiliateproperty, returns Affiliate
instance (if exists)django 1.7, 1.8 supportpython 3.4 supporttests are addedbackwards incompatibleIssues: #1, #3, #4, #6, #8v0.1.1 (2015-01-15)uploaded to pypismall bug fixesv0.1.0 (2014-04-29)affiliate modelstatistics modelsmeans for withdraw request