Question

I'm making a website in django. My website will have both paid and unpaid content. I have no idea how to open some features only for paid users or how to protect my premium data from unpaid users. The possible solutions i can think of are :

  • Create separate databases for paid and unpaid users.
  • Mark permission when user sign up on a website.
  • Make different models for paid & unpaid users.
  • Define different views.

Please help me. i know for some for you this will be a noobish question but i have stuck on this and i have no idea how to proceed.

Was it helpful?

Solution

On a broad level, you will first want to use groups, each with separate permissions. Documentation about Django groups can be found here. Essentially, you create two different groups (paid and unpaid) with different permissions in each. That same page includes documentation on permissions as well.

From there, you can go about it two ways. If you're going to have entirely different views that are accessible to different groups of users, you use some kind of @permission_required or @group_required) (or Mixins, for class-based views). Using these, you could decorate premium views and require a premium user to access the view. You can find further discussion of that in this blog post.

The second way would be to use template tags to show/hide certain premium information. This would be if both groups of users could view all the pages, but the premium users would be able to see some extra content. Here, the idea is similar to above but executed at the template level. You put a {% if perms.premium %} tag around a section of content that you only want premium users to see.

Bottom line: don't use separate databases or separate models. That's probably more headache than it's worth. You can get a little fancier than what I've shown (i.e. by altering the context that is passed to the template depending on the user group), but this should give you a decent start.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top