Skip to content

Commit 7bfb4cf

Browse files
authored
Single Model.update() instead of update_from_kwargs and setattr_and_save (#822)
1 parent 9e7777a commit 7bfb4cf

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

{{ cookiecutter.name }}/src/app/models.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ def __str__(self) -> str:
2828
def get_contenttype(cls) -> ContentType:
2929
return ContentType.objects.get_for_model(cls)
3030

31-
def update_from_kwargs(self, **kwargs: dict[str, Any]) -> None:
32-
"""A shortcut method to update model instance from the kwargs."""
31+
def update(self, **kwargs: "Any") -> "models.Model":
3332
for key, value in kwargs.items():
3433
setattr(self, key, value)
3534

36-
def setattr_and_save(self, key: str, value: Any) -> None:
37-
"""Shortcut for testing -- set attribute of the model and save"""
38-
setattr(self, key, value)
39-
self.save()
35+
self.save(update_fields=kwargs.keys())
36+
37+
return self
4038

4139
@classmethod
4240
def get_label(cls) -> str:

0 commit comments

Comments
 (0)