I would create an abstract class to hold the share values, extend from that for your n shared fields, use those as OneToOne in your user profile, and then have methods in the userprofile to determine if the field should be shown. Something like this (assumes you have the code to figure out if a user is public, fof, friend, or friend list)
On Wednesday, February 22, 2017 at 2:14:48 PM UTC+2, Alex Richards wrote:
-- class SharedField(models.Model):
share_with = models.IntegerField(choices=((1,'Public'),(2,'FoF'),(3,'Friend'),(4,'Friend List')))
class Meta:
abstract = True
class Email(SharedField):
email = models.EmailField()
class UserProfile(models.Model):
email = models.OneToOne(Email)
def get_relationship_level(self, request_user):
if request_user in self.friend_list:
return 4
elif request_user in self.friends:
return 3
elif request.user in self.fof:
return 2
else:
return 1
def get _email_for_user(self, request_user):
friend_level = self.get_relationship_level(request_user)
if friend_level >= self.email.share_with:
return self.email.email
return None
On Wednesday, February 22, 2017 at 2:14:48 PM UTC+2, Alex Richards wrote:
I want to implement privacy settings on my extended UserProfile Model where the user can decide who can see his field (say email for now).The options looks something like this,
public - any one can view his emailfriends_of_friends - only friends and friends of friends can view his emailfriends - only his friends can view his emailfriend_list - only a list of friends (pre defined) can view his email.I want to implement the same for n fields in the Model (phone number, work, education, etc..).I don't need code but some directions to solve it. Code examples won't hurt.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3de44eec-3087-42dc-988b-995464397fb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment