# save only table fields that were passed onto the dictionary

**URL:** <https://forum.djangoproject.com/t/save-only-table-fields-that-were-passed-onto-the-dictionary/28724>\
**Category:** Using the ORM\
**Created:** [March 5, 2024, 9:28am UTC](https://forum.djangoproject.com/t/save-only-table-fields-that-were-passed-onto-the-dictionary/28724 "2024-03-05T09:28:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anjanesh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anjanesh/32/4583_2.png) [@anjanesh](https://forum.djangoproject.com/u/anjanesh)\
**Post date:** [March 5, 2024, 9:28am UTC](https://forum.djangoproject.com/t/save-only-table-fields-that-were-passed-onto-the-dictionary/28724/1 "2024-03-05T09:28:22Z")

</div>

I have a model like this :

```auto
class Person(models.Model):
    name = models.CharField(max_length=250, blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)

class Employee(models.Model):
    p = models.ForeignKey("Person", on_delete=models.CASCADE, blank=True, null=True)
    department = models.TextField(blank=True, null=True)
    hasResigned = models.IntegerField(blank=True, null=True)

```

I have pre-filled data like this :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/8/9/89a6630ab52f825cbdc84055e5189a252ccc0b41.png)

If I execute this, the fields not present in the dictionary get wiped out from the existing row. (NULL)

```auto
    e_dict = {}
    e_dict['id'] = 1
    e_dict['department'] = 'Engineering'
    emp = Employee(**e_dict)
    emp.save()

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/9/8/98bd42b905e8ce42ce88b1611ff93510ff590719.png)

I’m using the above code in a method for multiple update methods (and if `e_dict['id']` is 0 then `emp.save()` will create).

```auto
if 'hasResigned' in form:
    e_dict['hasResigned'] = server.get("hasResigned")

```

I want `emp.save()` to update only fields that were passed on in the dictionary.

---

<div class="post-metadata">

**Author:** ![antoinehumbert](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/antoinehumbert/32/14851_2.png) [@antoinehumbert](https://forum.djangoproject.com/u/antoinehumbert)\
**Post date:** [March 5, 2024, 10:12am UTC](https://forum.djangoproject.com/t/save-only-table-fields-that-were-passed-onto-the-dictionary/28724/2 "2024-03-05T10:12:04Z")

</div>

Hi.  
See the documenation for the save method ([Model instance reference | Django documentation | Django](https://docs.djangoproject.com/en/5.0/ref/models/instances/#saving-objects)).

You should use something like:

```auto
emp.save(force_update=True, update_fields=list(e_dict.keys()))

```
