-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ✨ referral app #6
base: master
Are you sure you want to change the base?
Conversation
class ReferralCode(models.Model): | ||
"""Referral Code model""" | ||
|
||
code = models.CharField(max_length=56, unique=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always put ForeignKey
models that are non-null first.
related_name='referral_codes', | ||
on_delete=models.CASCADE, | ||
) | ||
created_at = models.DateTimeField(auto_now_add=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add an is_active = models.BooleanFIeld(...)
field as well.
We will need to limit the number of referral codes a user can create, otherwise they will just create infinitely many referral codes.
# isort: off | ||
|
||
|
||
class Referral(models.Model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AbstractReferral
referrer = models.ForeignKey( | ||
settings.AUTH_USER_MODEL, | ||
related_name='referrals', | ||
on_delete=models.CASCADE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have on_delete=models.SET_NULL
so that we can show the referral as deactivated or disabled, instead of just vanishing.
referred = models.OneToOneField( | ||
settings.AUTH_USER_MODEL, | ||
related_name='referred_by', | ||
on_delete=models.CASCADE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have on_delete=models.SET_NULL
so that we can show the referral as deactivated or disabled, instead of just vanishing.
def get_referrer_from_code(referral_code): | ||
referrer = None | ||
if htk_setting('HTK_REFERRAL_ALLOW_USERNAME') and referral_code.startswith( | ||
'@' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if we want this explicitly. Not sure yet.
|
||
def get_referrer(request): | ||
referrer = None | ||
key = 'referrer_id' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put this string in constants.
Let's use an all-caps value.
@@ -0,0 +1,10 @@ | |||
# HTK Imports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directory name should be plural referrals
HTK_REFERRAL_ALLOW_USERNAME = True | ||
|
||
# Redirect URL name for the referral URL | ||
HTK_REFERRAL_REDIRECT_URL_NAME = 'home' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set it to None and require the developer to configure something. If it's not set, redirect to /
def process_response(self, request, response): | ||
if self.referrer: | ||
request.session['referrer_id'] = self.referrer.id | ||
response.set_cookie('referrer_id', self.referrer.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use all caps for cookie names; also define a constants file for magic strings
No description provided.