-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove try/catch when create/upadate obj
- Loading branch information
GiuseppeNovielli
committed
Sep 9, 2024
1 parent
86684ab
commit 439f7d3
Showing
2 changed files
with
33 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
from django.conf import settings | ||
from django.forms.models import model_to_dict | ||
|
||
def remove_many_to_many(serializer, validated_data, **kwargs): | ||
for field in serializer.Meta.model._meta.many_to_many: | ||
if field.name in validated_data: | ||
del validated_data[field.name] | ||
return validated_data | ||
return validated_data | ||
|
||
|
||
# DEBUG | ||
def print_debug(message): | ||
drf_full_clean = getattr(settings, 'DRF_FULL_CLEAN', {}) | ||
if not drf_full_clean.get('DEBUG', False): | ||
return | ||
print('\nDRF_FULL_CLEAN -> {}'.format(message)) | ||
|
||
|
||
def instance_to_dict(instance): | ||
value_to_dict = None | ||
try: | ||
value_to_dict = model_to_dict(instance) | ||
except: | ||
try: | ||
value_to_dict = instance.__dict__ | ||
except: | ||
pass | ||
return value_to_dict |