Nurzhan Nogerbek
Nurzhan Nogerbek

Reputation: 5246

Django referral system with pinax-referrals?

I am trying to create referral system in my Django project. I found very interesting app (pinax-referrals) for this task and want to test it.

From documentation its not clear how correctly to use it and there is no example. As I understand we need make next steps:

1) Create Profile models with such code:

from django.contrib.auth.models import User
from django.dispatch import receiver
from account.signals import user_signed_up  # django-user-account app
from pinax.referrals.models import Referral

class Profile(models.Model):
    user = models.OneToOneField(User,on_delete=models.CASCADE)
    referral = models.OneToOneField(Referral, null=True, on_delete=models.CASCADE)

@receiver(user_signed_up)
def handle_user_signed_up(sender, user, form, **kwargs):
    Referral.create(redirect_to=user.profile.get_absolute_url())

2) Сreate custom signup view:

from account.views import SignupView
from pinax.referrals.models import Referral


class RegistrationView(SignupView):

    def after_signup(self, form):
        super(RegistrationView, self).after_signup(form)
        Referral.record_response(self.request, "USER_SIGNUP")

How correct are my steps? Could you give a simple example?

Upvotes: 5

Views: 1914

Answers (2)

Elijah
Elijah

Reputation: 1

Have tried to use your idea on this but I'm getting some errors

File "C:\Users\n\PycharmProjects\Elijahs_Agnes\venv\lib\site-packages\django\db\models\query.py", line 435, in get
    raise self.model.DoesNotExist(
App1.models.Profile.DoesNotExist: Profile matching query does not exist.

and

File "C:\Users\n\AppData\Local\Programs\Python\Python38\lib\logging\config.py", 

line 570, in configure
        raise ValueError('Unable to configure handler '
    ValueError: Unable to configure handler 'debug'

i'm using this logger

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'simple': {
            'format': '[%(asctime)s] | %(levelname)s | %(message)s',
            'datefmt': '%d/%b/%Y %H:%M:%S',
        },
    },
    'handlers': {
        'debug': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': 'logging/debug.log',
            'maxBytes': 1024*1024*5,
            'formatter': 'simple',
        },
        'error': {
            'level': 'ERROR',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': 'logging/error.log',
            'maxBytes': 1024*1024*5,
            'formatter': 'simple',
        },
    },
    'loggers': {
        'django': {
            'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
            'handlers': ['debug', 'error'],
        },
    },
}

Upvotes: 0

Nurzhan Nogerbek
Nurzhan Nogerbek

Reputation: 5246

As I see this question is interesting for some people. For that's why I decided to share information. Several years ago I create a simple Django project which uses pinax-referrals package for the referral system. I hope this project could be helpful to someone.

Upvotes: 5

Related Questions