[Fixed]-Need Assistane in converting django model admin save method to Django Rest Framework

1๐Ÿ‘

โœ…

When it is one field it is still acceptable, but if I need to do for a model where it has lets say 20 fields and I update only one field among those so then I need to specify all the field in my update method.

This is simply solved with:

for attr in ('job_category', ...):
    setattr(obj, attr, validated_data.get(attr, getattr(obj, attr))

Note that you could also loop on validated_data.keys() to make it more generic.

๐Ÿ‘คLinovia

Leave a comment