Skip to content
Snippets Groups Projects
Commit c65d768e authored by jackie / Andrea Ida Malkah Klaura's avatar jackie / Andrea Ida Malkah Klaura
Browse files

use .set instead of direct assessment for ManyToManyField

parent 2f91ad60
Branches
Tags
No related merge requests found
......@@ -274,12 +274,12 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer):
show = Show.objects.create(**validated_data)
# Save many-to-many relationships
show.owners = owners
show.category = category
show.hosts = hosts
show.language = language
show.topic = topic
show.musicfocus = musicfocus
show.owners.set(owners)
show.category.set(category)
show.hosts.set(hosts)
show.language.set(language)
show.topic.set(topic)
show.musicfocus.set(musicfocus)
show.save()
return show
......@@ -306,12 +306,12 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer):
# Only superusers may update the following fields
if user.is_superuser:
instance.owners = validated_data.get('owners', instance.owners)
instance.category = validated_data.get('category', instance.category)
instance.hosts = validated_data.get('hosts', instance.hosts)
instance.language = validated_data.get('language', instance.language)
instance.topic = validated_data.get('topic', instance.topic)
instance.musicfocus = validated_data.get('musicfocus', instance.musicfocus)
instance.owners.set(validated_data.get('owners', instance.owners))
instance.category.set(validated_data.get('category', instance.category))
instance.hosts.set(validated_data.get('hosts', instance.hosts))
instance.language.set(validated_data.get('language', instance.language))
instance.topic.set(validated_data.get('topic', instance.topic))
instance.musicfocus.set(validated_data.get('musicfocus', instance.musicfocus))
instance.type = validated_data.get('type', instance.type)
instance.fundingcategory = validated_data.get('fundingcategory', instance.fundingcategory)
instance.predecessor = validated_data.get('predecessor', instance.predecessor)
......@@ -466,4 +466,4 @@ class NoteSerializer(serializers.ModelSerializer):
except ObjectDoesNotExist:
pass
return instance
\ No newline at end of file
return instance
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment