I hereby claim:
- I am synotna on github.
- I am synotna (https://keybase.io/synotna) on keybase.
- I have a public key ASCfx3g3WgnIUJbeYEuYrvOfqZ0fVqrTIBLEuUMznytxHQo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
class FieldPermissionsMixin(object): | |
""" | |
A Serializer mixin for controlling which fields are included based on user permissions | |
Usage: | |
class MySerializer(FieldPermissionsMixin, serializers.ModelSerializer): | |
class Meta: | |
model = MyModel | |
field_permissions = { | |
'field': ['app.permission'], |
def bulk_update_or_create(self, channels, *key_fields): | |
if len(key_fields) == 1: | |
key_field = key_fields[0] | |
key_to_object_mapping = {channel[key_field]: channel for channel in channels} | |
lookup = {'{}__in'.format(key_field): list(key_to_object_mapping)} | |
existing = self.filter(**lookup) | |
existing_keys = existing.values_list(key_field, flat=True) | |
to_create = [self.model(**channel) for channel in channels | |
if channel[key_field] not in existing_keys] | |
self.bulk_create(to_create, batch_size=1000) |
Want to exclude patterns of files at any folder depth?
Pulling your hair out because .dockerignore (Go filepath.Match) sucks?
Don't waste time with .dockerignore
Make use of tar's pattern matching together with Docker's tar support and save your sanity!
def combine_q_or(q_objects=None): | |
if q_objects is None: | |
q_objects = [] | |
if len(q_objects): | |
return reduce(OR, q_objects) | |
return Q() |