python - Django Rest Framework Bulk Update -


i have been dealing problem while , cannot seem fix it, there 3 steps doing this

1: first uploading images via ajax post
2: inserting campaign
3: want update images table foreign key of ads

this means when serializer.save() being called success, make bulk update in images table ads.id

here code:

def create(self, request, *args, **kwargs):     #data = json.dumps(request.data)     user = self.request.user     if user.groups.filter(name='advertisers').exists():         serializer = campaignserializer(data=request.data)          adsid = adsimages.objects.filter(id__in=self.request.data["adsimages"][0]["image"])          if serializer.is_valid():             serializer.save(advertiser=self.request.user)             ad_id = serializer.data['ads'][0]['id']              ad in adsid:                 adsimagesserializer(adsimages,data=ad_id, partial=true)              return response(serializer.data, status=status.http_201_created,)         else:             return response(serializer.errors, status=status.http_400_bad_request)     else:         return response({                             'status':'unauthorized',                             'message':'this account not authorized request'                     }, status=status.http_401_unauthorized)     return super(campaignstart, self).perform_create(serializer) 

adsid = adsimages.objects.filter(id__in=self.request.data["adsimages"][0]["image"])

this get's images id's uploaded, it's dictionary

for ad in adsid:        adsimagesserializer(adsimages,data=ad_id, partial=true) 

here trying make foreach image["id"] update column of ads ad_id

and it's not working, need in here


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -