Okay so imagine I have these 2 model class
class Vendor(models.Model):
created_at = models.DateTimeField(auto_now_add = True, blank=True, null=True)
vendor_name = models.CharField(max_length = 50)
vendor_acronym = models.CharField(max_length = 3)
class Vendor_Details(models.Model):
created_at = models.DateTimeField(auto_now_add = True, blank=True, null=True)
vendor_name = models.ForeignKey(Vendor, on_delete = models.CASCADE)
vendor_number = models.CharField(max_length = 75, blank = True, null = True)
office_address = models.CharField(max_length = 75, blank = True, null = True)
owner_name = models.CharField(max_length = 25, blank = True, null = True)
Pardon if there’s any mistake in the code, this is just for example purposes
Now let’s say there’s user A that’s the Person in Charge of Vendor A. I want that person to only be able to see Vendor_Details of Vendor A and only that. Am I able to do it in Django or is it more appropiate to do such thing on the database level? If I’m able to do such thing with the blessings of Django, can someone point me into the light? I’ve seen a couple of threads / article flying around saying “Postgres Row-Level Security”, but I’m using MySQL
I already have an idea (no idea to implement it tho lmao), which is to assign vendor_acronym to each user. And whenever I want to View say the details, I’ll just filter the queryset. But there are a couple set backs tho
- I have to do it in every single view
- If the user just modify the url, they’ll still be able to see other details.
Anyway, thank you for whoever reply to this question!