I have a model in django that have a boolean private/public attribute:
class TestModel(models.Model):
name = models.CharField()
is_public = models.BooleanField(default=False)
I want that every-time I query this model in an application it returns only public instances to the common user and all available instances to the super-user.
How and where I need to implement such functionality?
You implement that logic at the view layer, probably with a custom manager.
Your manager would look something like this:
Your model would look something like:
You could then write a function that picked the right manager:
Then in your view you could use: