A
A
Alexey Belov2018-04-17 12:04:08
Python
Alexey Belov, 2018-04-17 12:04:08

How to change update method for nested serializer?

5ad5b83386381620939656.jpeg
How to write update() correctly, I have a large number of fields, isn't there another method?

class ProfileSerializer(serializers.ModelSerializer):
    legal = LegalSerializer(many=False)
    tech = TechSerializer(many=False)
    marketing = MarketingSerializer(many=False)
    finance = FinanceSerializer(many=False)
    translation_and_content = ContentSerializer(many=False)
    interests = InterestsSerializer(many=False)
    langs = LanguageSerializer(many=False)
    socials = SocialSerializer(many=True)

    class Meta:
        model = get_user_model()
        exclude = ('is_staff', 'is_active', 'date_joined', 'password',
                   'last_login', 'user_permissions', 'groups', 'is_superuser')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Belov, 2018-04-17
@Alenorze

legal = validated_data.get('legal')
        instance.legal.legal_audit = legal.get('legal_audit')
        instance.legal.taxation_ico = legal.get('taxation_ico')
        instance.legal.security_regulation = legal.get('security_regulation')
        instance.legal.company_setup = legal.get('company_setup')
        instance.legal.save()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question