I'm writing an user-driven app with several zones to it. I want to allow users to customise their messaging settings so they only get emails on the parts and actions they care about. I've drawn up the following Class
:
class EmailSetting(models.Model):
user = models.ForeignKey(User, related_name="%(class)s_related_user")
key = models.CharField(max_length=50)
value = models.BooleanField()
This is to be used by a method called get_users(key, default)
, which should return a list of users. For example, if I ask for a list of users that are subbed in on a key="new_post", default=False
, I should get a list of Users where they have an EmailSetting with a value of True for that key. That's simple enough because I can just use the EmailSetting model.
If the default is True, things appear to be harder. I've never done anything more complicated than basic look-ups with Models, so I need a hand.
From a full list of Users, I need to remove ones with a False EmailSetting. Short of doing another query on EmailSetting looking for False entries and iteratively cutting them out of the first queryset, I can't see how to do this...
... But there must be another way because that stinks.