Last active
February 20, 2017 15:44
-
-
Save philippeowagner/5fc23a4cd28df78c0d9d to your computer and use it in GitHub Desktop.
Django > reload current object from DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Object(models.Model): | |
| def reload(self): | |
| """ | |
| Reload object from the database | |
| """ | |
| return Object.objects.get(pk=self.pk) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is
Model.refresh_from_dbfunction in Django for this: https://docs.djangoproject.com/en/1.10/ref/models/instances/#django.db.models.Model.refresh_from_db