# Update database - Making queries

**URL:** <https://forum.djangoproject.com/t/update-database-making-queries/16503>\
**Category:** Using the ORM\
**Created:** [October 17, 2022, 11:21am UTC](https://forum.djangoproject.com/t/update-database-making-queries/16503 "2022-10-17T11:21:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Goktuginal](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/goktuginal/32/8648_2.png) [@Goktuginal](https://forum.djangoproject.com/u/Goktuginal)\
**Post date:** [October 17, 2022, 11:21am UTC](https://forum.djangoproject.com/t/update-database-making-queries/16503/1 "2022-10-17T11:21:29Z")

</div>

Hello everyone,

When I click form button, I add new sample to db. And also, I want to update another specific fields of another rows in db at the same time. There are a few rows which have same p\_id.

What I want to do is to make YES **is\_index\_sample** of the rows matching **hiddenIndexID**. Make those that don’t match NO. In the last step, assigning NO to **is\_index\_sample** of the new sample value I created. But **secondItem.is\_index\_sample** part is not working. How can I fix it? Thank you in advance.

**views.py**

```auto
sample = Samples()
cycle = Samples.objects.filter(patientid = request.POST.get('p_id'));
check = request.POST.get('hiddenIndexID');

```

```auto
if check is not None:
   for secondItem in cycle:
      if str(secondItem.id) == check:
         secondItem.is_index_sample = 'Yes';
      else:
         secondItem.is_index_sample = 'No';
   sample.is_index_sample = 'No';

sample.save()

messages.success(request, "New sample is added successfully!")

return HttpResponseRedirect("/")

```

---

<div class="post-metadata">

**Author:** ![alchermd](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/alchermd/32/1215_2.png) [@alchermd](https://forum.djangoproject.com/u/alchermd)\
**Post date:** [October 17, 2022, 11:27am UTC](https://forum.djangoproject.com/t/update-database-making-queries/16503/2 "2022-10-17T11:27:28Z")

</div>

I think you’re missing a `secondItem.save()` at the end of your loop

---

<div class="post-metadata">

**Author:** ![alchermd](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/alchermd/32/1215_2.png) [@alchermd](https://forum.djangoproject.com/u/alchermd)\
**Post date:** [October 17, 2022, 11:39am UTC](https://forum.djangoproject.com/t/update-database-making-queries/16503/4 "2022-10-17T11:39:18Z")

</div>

Yes, it is possible. Any changes you do to a model instance won’t get persisted if you don’t call its `.save()` method.

---

<div class="post-metadata">

**Author:** ![Goktuginal](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/goktuginal/32/8648_2.png) [@Goktuginal](https://forum.djangoproject.com/u/Goktuginal)\
**Post date:** [October 17, 2022, 11:40am UTC](https://forum.djangoproject.com/t/update-database-making-queries/16503/5 "2022-10-17T11:40:02Z")

</div>

Hello, I fixed the problem with

```auto
Samples.objects.filter(patientid=getPOST).update(is_index_sample=Yes')

```
