My Models:
class PromoNotification(models.Model):
title = models.CharField(_('Title'), max_length=200)
content = models.TextField(_('Content'))
users = models.ManyToManyField(User, blank=True, null=True)
groups = models.ManyToManyField(Group, blank=True, null=True)
I want to publish there items to templates with some permissions. The template is only show the notifications for users who are in list (users or/and group). What should I do? Thank you for any help. Please show me some codes if you can.
You might use a custom manager, which makes it easier to do this user filtering in multiple views.
Hook up the manager to your PromoNotification model:
Then in your view:
You can read more about custom managers in the docs: http://www.djangoproject.com/documentation/models/custom_managers/