[Answer]-How to update only one field instead creating another object – django 1.4

1👍

Your code will work as expected if you’re looking up a Location by a unique identifier instead of trying to match all fields:

location, created = Location.objects.get_or_create(pk=pk)
if created:
   num_of_new_locs+=1 #number of new locations increased
else:
   location.url= loc_fields['url']
   location.locationname = loc_fields['locationname']
   location.desc = loc_fields['desc']
   location.str_hnr = loc_fields['str_hnr']
   location.save()

Leave a comment