Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
20d1cb33
Kaydet (Commit)
20d1cb33
authored
Haz 21, 2016
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #26787 -- Documented deleting and reloading of model instance fields.
Thanks Julien Hartmann for the report.
üst
9c2d5a8d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
0 deletions
+28
-0
instances.txt
docs/ref/models/instances.txt
+12
-0
1.10.txt
docs/releases/1.10.txt
+3
-0
tests.py
tests/basic/tests.py
+13
-0
No files found.
docs/ref/models/instances.txt
Dosyayı görüntüle @
20d1cb33
...
...
@@ -128,6 +128,18 @@ in the ``from_db()`` method.
Refreshing objects from database
================================
If you delete a field from a model instance, accessing it again reloads the
value from the database::
>>> obj = MyModel.objects.first()
>>> del obj.field
>>> obj.field # Loads the field from the database
.. versionchanged:: 1.10
In older versions, accessing a deleted field raised ``AttributeError``
instead of reloading it.
.. method:: Model.refresh_from_db(using=None, fields=None)
If you need to reload a model's values from the database, you can use the
...
...
docs/releases/1.10.txt
Dosyayı görüntüle @
20d1cb33
...
...
@@ -884,6 +884,9 @@ Miscellaneous
* The ``_base_manager`` and ``_default_manager`` attributes are removed from
model instances. They remain accessible on the model class.
* Accessing a deleted field on a model instance, e.g. after ``del obj.field``,
reloads the field's value instead of raising ``AttributeError``.
.. _deprecated-features-1.10:
Features deprecated in 1.10
...
...
tests/basic/tests.py
Dosyayı görüntüle @
20d1cb33
...
...
@@ -421,6 +421,19 @@ class ModelTest(TestCase):
# hash)
hash
(
Article
())
def
test_delete_and_access_field
(
self
):
# Accessing a field after it's deleted from a model reloads its value.
pub_date
=
datetime
.
now
()
article
=
Article
.
objects
.
create
(
headline
=
'foo'
,
pub_date
=
pub_date
)
new_pub_date
=
article
.
pub_date
+
timedelta
(
days
=
10
)
article
.
headline
=
'bar'
article
.
pub_date
=
new_pub_date
del
article
.
headline
with
self
.
assertNumQueries
(
1
):
self
.
assertEqual
(
article
.
headline
,
'foo'
)
# Fields that weren't deleted aren't reloaded.
self
.
assertEqual
(
article
.
pub_date
,
new_pub_date
)
class
ModelLookupTest
(
TestCase
):
def
setUp
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment