I agree with @nnaelle that adding an is_subscribed
attribute to your user model is a good option for ensuring that the subscribe button isn't shown to your users that are already subscribed. Adding this attribute means that, if you haven't already, you'll need to extend the user model in your models.py
to keep track of whether they are subscribed. This looks something like this (as in the Django docs):
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.OneToOneField(User)
is_subscribed = models.BooleanField(default=False)
The new user model can then be accessed by, say, the views in views.py
:
from my_app.models import UserProfile
def index(request):
user = request.user
userprofile = UserProfile.objects.get(user=user)
...
You can (and might want to) avoid having to access the user profile that way, however, by making your new user model the default for your app under settings.py
as described in the docs for substituting custom user models. Then after passing in the new user model to the view, you can do a check for subscription status using {% if not userprofile.is_subscribed %}
and only show the subscription button for those who aren't subscribed:
{% if not userprofile.is_subscribed %}
<div ...></div>
{% endif %}
Feel free to give me your feedback!