File in nested serializer

78 views
Skip to first unread message

narendra...@gmail.com

unread,
Jun 15, 2021, 1:18:22 AM6/15/21
to Django users
Hi Folks,
I'm having a problem to insert a data in nested serializers with FileField. If anybody know the idea of doing that would you guys please just help me out. I googled it for the solution but found the problem asked but not a solution. And somewhere in git i found that it is hard to manged with nested serializers with file field. 

Nikeet NA

unread,
Jun 15, 2021, 5:04:19 AM6/15/21
to Django users

narendra thapa

unread,
Jun 15, 2021, 8:37:04 PM6/15/21
to django...@googlegroups.com
Actual problem is nested serializer is not accepting a QueryDIct data it accepts only the parent data and delete the child automatically. when i parse the QueryDIct data to JSON json.dumps() it will accept the child one but problem here is json.dumps() cannot convert InMEmoryField data type. So what will be the best way to do it. If you have some idea please share with me

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/588eed3a-7900-443c-9e9f-124136ba3933n%40googlegroups.com.

narendra thapa

unread,
Jun 15, 2021, 8:37:29 PM6/15/21
to django...@googlegroups.com
Actual problem is nested serializer is not accepting a QueryDIct data it accepts only the parent data and delete the child automatically. when i parse the QueryDIct data to JSON json.dumps() it will accept the child one but problem here is json.dumps() cannot convert InMEmoryField data type. So what will be the best way to do it. If you have some idea please share with me


On Tue, Jun 15, 2021 at 2:49 PM Nikeet NA <nik...@exiverlabs.co.in> wrote:
--

Nikeet NA

unread,
Jun 15, 2021, 10:41:55 PM6/15/21
to django...@googlegroups.com
Can you show me your nested serializer code.

narendra thapa

unread,
Jun 21, 2021, 1:14:44 AM6/21/21
to django...@googlegroups.com
class CompanySerializer(serializers.ModelSerializer):
    company_contact = CompanyContactDetailsGet(many=True,required=False)
    company_logo_details = CompanyLogoGet(many=True,required=False)    
   
    class Meta:
        model = company_details
        fields = ('id','company_name','company_address','company_email','company_contact','company_logo_details')

    def create(self,validated_data):
        print("company_data",validated_data)
        company_contact_no = validated_data.pop('company_contact')
        print("company_contact",company_contact_no)
        # company_logo_data = validated_data.pop('company_logo_details')
        with transaction.atomic():
            company = company_details.objects.create(**validated_data)
            # company_logo.objects.filter(Q(is_deleted_flag='n') | Q(company=company)).update(is_deleted_flag='y')        
            # for data in company_logo_data:
            #     companyLogo = company_logo.objects.create(company=company,**company_logo_data)

            for contact in company_contact_no:
                print("contactsss",contact,company)
                # contact['company'] = company
                company_contact_details.objects.create(company=company,**contact)
            
        return validated_data

Reply all
Reply to author
Forward
0 new messages