1👍
Django Authentication System provides the ability to delegate users into groups with permissions.
The admin interface tackles with this very smoothly
You can, of course, achieve the same result programmatically.
Then, in your view, you can check if the logged in user has permission to add a new object in the models SellProduct
and BuyProduct
of the application marketplace
:
from django.contrib.auth.decorators import login_required
@login_required
def create_sale_view(request):
if request.user.has_perm(
"marketplace.add_sellproduct"
) and request.user.has_perm("marketplace.add_buyproduct"):
# The user can buy and sell
pass
else:
# The user cannot buy nor sell
pass
0👍
class CustomUser(AbstractUser):
is_customer = models.BooleanField(default = False)
is_seller = models.BooleanField(default = False)
class Customer(models.Model):
buyer = models.OneToOneField(CustomUser, on_delete= models.CASCADE)
address = models.TextField()
class Seller(models.Model):
seller = models.OneToOneField(CustomUser, on_delete= models.CASCADE)
store = models.CharField(max_length = 90)
You can use this approach and block the customer or seller’s access using decorators. I’ve used this method to build my website.
- [Answered ]-Django Cache Machine: Enabling QuerySet caching on third-party or core Models
- [Answered ]-Redirect certain user to certain view in django
- [Answered ]-Django query database and send data to template
Source:stackexchange.com