4

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?

Nurzhan Nogerbek
  • 4,806
  • 16
  • 87
  • 193
  • I think their [documentation](https://github.com/pinax/pinax-referrals#documentation) is pretty clear. Try following the steps they outlined and post a question if you have a specific problem. Otherwise this question is too broad to be answered here. – Selcuk May 21 '18 at 23:56
  • 1
    @Selcuk hello! :) Its not clear for me how to start. Lets say when user signs up successfully triggered `handle_user_signed_up` function which create Referral. But I don't sure where exactly I need to `redirect_to`? Can you check profile model at least, pls? – Nurzhan Nogerbek May 22 '18 at 04:26
  • @NurzhanNogerbek , did you find solution for your own question? and can you share it ? – Vadim Dec 18 '19 at 16:24
  • @Vadim hello! Unfortunately, I don't remember all the steps which I did. As I remember I used `pinax-referrals` package. More details you can find in this working [project](https://github.com/NogerbekNurzhan/BonusDesk). I hope it could help you! – Nurzhan Nogerbek Dec 18 '19 at 16:33

2 Answers2

4

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.

Nurzhan Nogerbek
  • 4,806
  • 16
  • 87
  • 193
0

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'],
        },
    },
}
Elijah
  • 1
  • Welcome to SO, usually when you post an answer the answer is not supposed to talk about having errors when trying to follow someone's idea as this won't help others. – dankilev Jul 04 '21 at 21:40