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
ec08d62a
Kaydet (Commit)
ec08d62a
authored
Şub 22, 2014
tarafından
Adam Kaliński
Kaydeden (comit)
Tim Graham
Mar 24, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22048 - Enhanced docs to cover nonexistent one-to-one relationships.
Thanks EvilDMP for the suggestion.
üst
60d2dde2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
fields.txt
docs/ref/models/fields.txt
+9
-0
one_to_one.txt
docs/topics/db/examples/one_to_one.txt
+11
-4
No files found.
docs/ref/models/fields.txt
Dosyayı görüntüle @
ec08d62a
...
@@ -1469,6 +1469,15 @@ your resulting ``User`` model will have the following attributes::
...
@@ -1469,6 +1469,15 @@ your resulting ``User`` model will have the following attributes::
>>> hasattr(user, 'supervisor_of')
>>> hasattr(user, 'supervisor_of')
True
True
A ``DoesNotExist`` exception is raised when accessing the reverse relationship
if an entry in the related table doesn't exist. For example, if a user doesn't
have a supervisor designated by ``MySpecialUser``::
>>> user.supervisor_of
Traceback (most recent call last):
...
DoesNotExist: User matching query does not exist.
.. _onetoone-arguments:
.. _onetoone-arguments:
Additionally, ``OneToOneField`` accepts all of the extra arguments
Additionally, ``OneToOneField`` accepts all of the extra arguments
...
...
docs/topics/db/examples/one_to_one.txt
Dosyayı görüntüle @
ec08d62a
...
@@ -61,10 +61,17 @@ A Place can access its restaurant, if available::
...
@@ -61,10 +61,17 @@ A Place can access its restaurant, if available::
p2 doesn't have an associated restaurant::
p2 doesn't have an associated restaurant::
>>> p2.restaurant
>>> from django.core.exceptions import ObjectDoesNotExist
Traceback (most recent call last):
>>> try:
...
>>> p2.restaurant
DoesNotExist: Restaurant matching query does not exist.
>>> except ObjectDoesNotExist:
>>> print("There is no restaurant here.")
There is no restaurant here.
You can also use ``hasattr`` to avoid the need for exception catching::
>>> hasattr(p2, 'restaurant')
False
Set the place using assignment notation. Because place is the primary key on
Set the place using assignment notation. Because place is the primary key on
Restaurant, the save will create a new restaurant::
Restaurant, the save will create a new restaurant::
...
...
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