Home > Net >  How I can implement this logic in Django where seller user can only sale products and buyer can only
How I can implement this logic in Django where seller user can only sale products and buyer can only

Time:09-26

I have scenario in which seller can only sale products while buyer can only buyer products I am new in Django I have no idea how can i implement this logic?

CodePudding user response:

set Boolean is_seller and is_buyer in User model. check whenever user is try to buy or sale then check in Function by checking those two flag and decide to let them proceed or return response like You dont have permission to perform this action

CodePudding user response:

Django has a whole permission system that would work for this. Essentially you'd create "seller" and "buyer" groups and then give them the custom permissions you want. Then in the views you'd use user.has_perm('allowed_to_buy') (for example) to check that permission before performing the action. The permissions should be granted to the groups and the users added to those groups (then you can also have a user who's both a buyer and a seller, if you wanted).

  • Related