mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 04:09:16 +02:00
Added helper to filter queryset by privacy level
This commit is contained in:
parent
2a3f43ecb1
commit
3e277aad4f
2 changed files with 30 additions and 0 deletions
|
@ -12,3 +12,16 @@ PRIVACY_LEVEL_CHOICES = [
|
|||
def get_privacy_field():
|
||||
return models.CharField(
|
||||
max_length=30, choices=PRIVACY_LEVEL_CHOICES, default='instance')
|
||||
|
||||
|
||||
def privacy_level_query(user, lookup_field='privacy_level'):
|
||||
if user.is_anonymous:
|
||||
return models.Q(**{
|
||||
lookup_field: 'everyone',
|
||||
})
|
||||
|
||||
return models.Q(**{
|
||||
'{}__in'.format(lookup_field): [
|
||||
'me', 'followers', 'instance', 'everyone'
|
||||
]
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue