File in nested serializer

78 zobrazení
Preskočiť na prvú neprečítanú správu

narendra...@gmail.com

neprečítané,
15. 6. 2021, 1:18:2215. 6. 2021
komu: 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

neprečítané,
15. 6. 2021, 5:04:1915. 6. 2021
komu: Django users

narendra thapa

neprečítané,
15. 6. 2021, 20:37:0415. 6. 2021
komu: 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

neprečítané,
15. 6. 2021, 20:37:2915. 6. 2021
komu: 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

neprečítané,
15. 6. 2021, 22:41:5515. 6. 2021
komu: django...@googlegroups.com
Can you show me your nested serializer code.

narendra thapa

neprečítané,
21. 6. 2021, 1:14:4421. 6. 2021
komu: 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

Odpovedať všetkým
Odpovedať autorovi
Poslať ďalej
0 nových správ