Django membership project

i got your reprimand on the other post. its ok

so which should i use?

i am trying to build a web app where people register and join either the free Gold and silver membership. The number of posts that can be made by each user is depends if he is a free, gold or silver user. which method will be best to implement this. The django groups or user type.
remember that each of this users will have to log in and be able to join or change membership from there dashboard. pls your help will be really appreciated.

Groups are probably not the most effective means of handling this. (The intent and functionality of groups is that a User can be a member of multiple groups at the same time, which is not what I think you’re looking for.)

I would look at creating this using the “Profile” style of Extending the User Model. You don’t need to modify the existing model, you can create a separate model that exists with a One-to-One relationship with the User model, containing all the application-specific attributes for that User.


ok thank you.this is what i have done, i wanted to use email for the authentication so. i created a custume user model using the AbstractBaseUser.
i have also created the user profile…

class profile (models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
profile_image = models.ImageField(default=‘default.jpg’, upload_to = ‘profile_pics’)
date_of_birth = models.DateField(blank=True, null=True)
street = models.CharField(max_length = 100, blank = True, null=True)
city = models.CharField(max_length = 50, blank = True , null=True)
state = models.CharField(max_length = 50, blank = True, null=True)
phone = models.IntegerField ( blank = True, null=True)
zipcode = models.CharField(max_length = 8, blank = True, null=True)
country = models.CharField(max_length = 50, blank = True, null=True)
date_created = models.DateField(

def __str__(self):
    return self.user.first_name + " " + self.user.last_name + " "  + self.user.username

class Meta:
    verbose_name_plural = 'User Profiles'
    db_table = 'user_profiles'

i was now thinking of using the practical example here. How to Implement Multiple User Types with Django

Yes, that looks like a workable model as a start. (I’m not sure I would store phone number as an integer - many people are used to seeing phone numbers in a specific format, and unless you’re doing math on a phone number, there’s no reason not to store it in that format.)

However, if you are working with an international set of users, you might want to do a little more research in to how you should store an address.

For example, the full United States zip code is 9 digits. There are also multiple situations where you need two “street” lines instead of just one. (It does all really depend upon your specific needs - it’s possible that these edge cases won’t really affect you at all - but that’s a decision you should make at least knowing what the issues might be. Handling international addresses, names, and telephone numbers is hard.)


thank you . i have noted your corrections.
but there is a problem.
class User(AbstractUser):
is_free = models.BooleanField(default=False)
is_silver = models.BooleanField(default=False)
is_gold = models.BooleanField(default=False)

class Free(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)

class Silver(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)

it doesn’t seem to connect to my users created with (AbstractBaseUser) costume user model

what do i do

should i remove the costume user model. it seems like this tutorial has two different sign up forms. while i have already created one for my costume user model.

does this mean that i will have to remove the costume signup model (AbstractBaseModel) and its form in other to use the abstract user?
or is there a way i can use the AbstractUser with the AbstractBaseUser

Ok, this isn’t how I would recommend modelling this.

You’ve already established in your prior response that you’re going to have a profile model. Therefore, you don’t need to add anything to the User model itself - that’s the reason behind having the Profile model.

Also, my understanding is that a person can be one of “free”, “silver”, or “gold” - not more than one. If I’m right, then your Profile model associated with the membership level would more appropriately be something like:
(Note: I’m doing this strictly from memory, I have no idea what I may have wrong here - I’m just winging this at the moment.)

class Profile(models.Model):
    <all the fields you defined above>
    membership_level = models.ForeignKey('MembershipLevel', on_delete=models.PROTECT)

class MembershipLevel(models.Model):
    level_name = models.CharField(max_length=10)
    max_post_count = models.IntegerField()
    <any other fields that define what makes each membership level unique such as price>

You then load the MembershipLevel table with one row for each level. From what you’ve shown so far, you’re going to have three rows, one for each of “free”, “silver”, and “gold”.

(Also note: if you see how my code is displayed above, that’s because that code is between two lines consisting only of three backtick (`) characters. That preserves the formatting of the code in the post.)

You can get by with just one sign-up form. Your view will need to create both the Profile and your User object.

If you choose to stay with your custom User object, then you want to make sure that your Profile object has the OneToOne relationship with your User object and not the system default User object. (I also strongly recommend that you don’t name your custom User object “User”. Use something different like maybe “Member” - it’ll save you a lot of confusion later on.)


thanks ken, i have been doing some things by myself . see the things i have actually achieved.

I created two additional models.

membership_choices = (





class MembershipLevel(models.Model):
slug = models.SlugField()
level_name = models.CharField(choices = membership_choices,
default = ‘Free’)
max_post_count = models.IntegerField( default = 15)
price = models.CharField(max_length=10)

def __str__(self):
    return self.level_name

class UserMembership(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
membershiplevel = models.ForeignKey(MembershipLevel, on_delete = models.SET_NULL, null = True)

def str(self):

where the UserMembership model is foreign key in the profile model

subscription = models.ForeignKey(UserMembership, on_delete = models.SET_NULL, null = True )

Please how can i subscribe a user to a plan when click on the subscribe button.
and restrict the number of posts

In the general case, any time you’re trying to figure out how you want to do something, there are three fundamental questions to consider that require very specific answers.

  1. What does the user need to do to cause this desired action to occur?
  2. What exactly do you want to have happen?
  3. What do you want the user to see when they’re done?

So looking at these questions in the context of Subscribing a user to a plan -

  1. I’m going to guess that you want the user to press the subscribe button to start this process.
    After they do this, is there anything else that they might need to do? (Any other form or confirmation? Even if you do, you might want to ignore that for now, but it is helpful to at least acknowledge that it’s something to be done in the future.)

  2. Other than just setting the UserMembership model, is there anything else that needs to be done at the time the button is pushed?

  3. What is the user going to see after they’ve finished whatever process happens when they push Subscribe?

The specific and detailed answers are going to drive what needs to be done.

Your other question about restricting the number of posts is a completely separate issue. It’s not, strictly speaking, related at all to the subscription process.
If I were doing this, I would tie this in to whatever button or link the user clicks to add a post. So let’s say you have a button called “Add Post”. When a user clicks “Add Post”, you might normally take them to a page where they can add a post. What you want to add that that point is your check to see whether or not they’re eligible to add another post - but then you need to decide what’s going to happen if they’re not eligible to do so.

thanks a lot. in this case the user will have to make a payment. but there is a catch. i would have used stripe and its API. isn’t an option where i am from. i am opting for paystack but its python api is not beginner friendly and no tutorials how to use them paystack python API . my only option is to use is to use this javascript integrating pystack to django project to collect the payment . so when the user is done paying he is redirected to the dashboard and the plan he subscribed for activate

Thank you Ken for the help so far
:blush: :blush:

hi, have you been able to solve your intergrating paystack to django subscription issue, i’m acing the same issue now and there not enoough resource to help intergrate paystack to django

i saw this post integrating Paystack into your existing django project in some few simple step | Medium but it’s not actually what i wanted

yeah i solved it.
maybe you can open a thread on what you want to do so i can help resolve it

please you can help me with if you can i really need it now

Hi please how can i open a thread, should i just ask a question

Yes, you can use the “New Topic” button at the top of the page to create a new discussion thread.

okay thanks for your response

hi i just created a new topic on django membership project

Hi, it created already