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
fa2e1371
Kaydet (Commit)
fa2e1371
authored
Agu 20, 2013
tarafından
Simon Charette
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #21216 -- Allow `OneToOneField` reverse accessor to be hidden.
üst
c4db7f07
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
10 deletions
+34
-10
related.py
django/db/models/fields/related.py
+3
-5
1.7.txt
docs/releases/1.7.txt
+5
-0
models.py
tests/one_to_one_regress/models.py
+13
-2
tests.py
tests/one_to_one_regress/tests.py
+13
-3
No files found.
django/db/models/fields/related.py
Dosyayı görüntüle @
fa2e1371
...
@@ -960,6 +960,7 @@ class ManyToManyRel(object):
...
@@ -960,6 +960,7 @@ class ManyToManyRel(object):
class
ForeignObject
(
RelatedField
):
class
ForeignObject
(
RelatedField
):
requires_unique_target
=
True
requires_unique_target
=
True
generate_reverse_relation
=
True
generate_reverse_relation
=
True
related_accessor_class
=
ForeignRelatedObjectsDescriptor
def
__init__
(
self
,
to
,
from_fields
,
to_fields
,
**
kwargs
):
def
__init__
(
self
,
to
,
from_fields
,
to_fields
,
**
kwargs
):
self
.
from_fields
=
from_fields
self
.
from_fields
=
from_fields
...
@@ -1160,7 +1161,7 @@ class ForeignObject(RelatedField):
...
@@ -1160,7 +1161,7 @@ class ForeignObject(RelatedField):
# Internal FK's - i.e., those with a related name ending with '+' -
# Internal FK's - i.e., those with a related name ending with '+' -
# and swapped models don't get a related descriptor.
# and swapped models don't get a related descriptor.
if
not
self
.
rel
.
is_hidden
()
and
not
related
.
model
.
_meta
.
swapped
:
if
not
self
.
rel
.
is_hidden
()
and
not
related
.
model
.
_meta
.
swapped
:
setattr
(
cls
,
related
.
get_accessor_name
(),
ForeignRelatedObjectsDescriptor
(
related
))
setattr
(
cls
,
related
.
get_accessor_name
(),
self
.
related_accessor_class
(
related
))
if
self
.
rel
.
limit_choices_to
:
if
self
.
rel
.
limit_choices_to
:
cls
.
_meta
.
related_fkey_lookups
.
append
(
self
.
rel
.
limit_choices_to
)
cls
.
_meta
.
related_fkey_lookups
.
append
(
self
.
rel
.
limit_choices_to
)
...
@@ -1334,6 +1335,7 @@ class OneToOneField(ForeignKey):
...
@@ -1334,6 +1335,7 @@ class OneToOneField(ForeignKey):
always returns the object pointed to (since there will only ever be one),
always returns the object pointed to (since there will only ever be one),
rather than returning a list.
rather than returning a list.
"""
"""
related_accessor_class
=
SingleRelatedObjectDescriptor
description
=
_
(
"One-to-one relationship"
)
description
=
_
(
"One-to-one relationship"
)
def
__init__
(
self
,
to
,
to_field
=
None
,
**
kwargs
):
def
__init__
(
self
,
to
,
to_field
=
None
,
**
kwargs
):
...
@@ -1346,10 +1348,6 @@ class OneToOneField(ForeignKey):
...
@@ -1346,10 +1348,6 @@ class OneToOneField(ForeignKey):
del
kwargs
[
'unique'
]
del
kwargs
[
'unique'
]
return
name
,
path
,
args
,
kwargs
return
name
,
path
,
args
,
kwargs
def
contribute_to_related_class
(
self
,
cls
,
related
):
setattr
(
cls
,
related
.
get_accessor_name
(),
SingleRelatedObjectDescriptor
(
related
))
def
formfield
(
self
,
**
kwargs
):
def
formfield
(
self
,
**
kwargs
):
if
self
.
rel
.
parent_link
:
if
self
.
rel
.
parent_link
:
return
None
return
None
...
...
docs/releases/1.7.txt
Dosyayı görüntüle @
fa2e1371
...
@@ -289,6 +289,11 @@ Models
...
@@ -289,6 +289,11 @@ Models
* Explicit :class:`~django.db.models.OneToOneField` for
* Explicit :class:`~django.db.models.OneToOneField` for
:ref:`multi-table-inheritance` are now discovered in abstract classes.
:ref:`multi-table-inheritance` are now discovered in abstract classes.
* Is it now possible to avoid creating a backward relation for
:class:`~django.db.models.OneToOneField` by setting its
:attr:`~django.db.models.ForeignKey.related_name` to
`'+'` or ending it with `'+'`.
Signals
Signals
^^^^^^^
^^^^^^^
...
...
tests/one_to_one_regress/models.py
Dosyayı görüntüle @
fa2e1371
...
@@ -12,6 +12,7 @@ class Place(models.Model):
...
@@ -12,6 +12,7 @@ class Place(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the place"
%
self
.
name
return
"
%
s the place"
%
self
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Restaurant
(
models
.
Model
):
class
Restaurant
(
models
.
Model
):
place
=
models
.
OneToOneField
(
Place
)
place
=
models
.
OneToOneField
(
Place
)
...
@@ -21,6 +22,7 @@ class Restaurant(models.Model):
...
@@ -21,6 +22,7 @@ class Restaurant(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the restaurant"
%
self
.
place
.
name
return
"
%
s the restaurant"
%
self
.
place
.
name
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Bar
(
models
.
Model
):
class
Bar
(
models
.
Model
):
place
=
models
.
OneToOneField
(
Place
)
place
=
models
.
OneToOneField
(
Place
)
...
@@ -29,23 +31,32 @@ class Bar(models.Model):
...
@@ -29,23 +31,32 @@ class Bar(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s the bar"
%
self
.
place
.
name
return
"
%
s the bar"
%
self
.
place
.
name
class
UndergroundBar
(
models
.
Model
):
class
UndergroundBar
(
models
.
Model
):
place
=
models
.
OneToOneField
(
Place
,
null
=
True
)
place
=
models
.
OneToOneField
(
Place
,
null
=
True
)
serves_cocktails
=
models
.
BooleanField
(
default
=
True
)
serves_cocktails
=
models
.
BooleanField
(
default
=
True
)
@python_2_unicode_compatible
@python_2_unicode_compatible
class
Favorites
(
models
.
Model
):
class
Favorites
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
restaurants
=
models
.
ManyToManyField
(
Restaurant
)
restaurants
=
models
.
ManyToManyField
(
Restaurant
)
def
__str__
(
self
):
def
__str__
(
self
):
return
"Favorites for
%
s"
%
self
.
name
return
"Favorites for
%
s"
%
self
.
name
class
Target
(
models
.
Model
):
class
Target
(
models
.
Model
):
pass
pass
class
Pointer
(
models
.
Model
):
class
Pointer
(
models
.
Model
):
other
=
models
.
OneToOneField
(
Target
,
primary_key
=
True
)
other
=
models
.
OneToOneField
(
Target
,
primary_key
=
True
)
class
Pointer2
(
models
.
Model
):
class
Pointer2
(
models
.
Model
):
other
=
models
.
OneToOneField
(
Target
)
other
=
models
.
OneToOneField
(
Target
,
related_name
=
'second_pointer'
)
class
HiddenPointer
(
models
.
Model
):
target
=
models
.
OneToOneField
(
Target
,
related_name
=
'hidden+'
)
tests/one_to_one_regress/tests.py
Dosyayı görüntüle @
fa2e1371
...
@@ -2,7 +2,8 @@ from __future__ import unicode_literals
...
@@ -2,7 +2,8 @@ from __future__ import unicode_literals
from
django.test
import
TestCase
from
django.test
import
TestCase
from
.models
import
Place
,
Restaurant
,
Bar
,
Favorites
,
Target
,
UndergroundBar
from
.models
import
(
Bar
,
Favorites
,
HiddenPointer
,
Place
,
Restaurant
,
Target
,
UndergroundBar
)
class
OneToOneRegressionTests
(
TestCase
):
class
OneToOneRegressionTests
(
TestCase
):
...
@@ -125,11 +126,11 @@ class OneToOneRegressionTests(TestCase):
...
@@ -125,11 +126,11 @@ class OneToOneRegressionTests(TestCase):
[]
[]
)
)
self
.
assertQuerysetEqual
(
self
.
assertQuerysetEqual
(
Target
.
objects
.
filter
(
pointer2
=
None
),
Target
.
objects
.
filter
(
second_pointer
=
None
),
[
'<Target: Target object>'
]
[
'<Target: Target object>'
]
)
)
self
.
assertQuerysetEqual
(
self
.
assertQuerysetEqual
(
Target
.
objects
.
exclude
(
pointer2
=
None
),
Target
.
objects
.
exclude
(
second_pointer
=
None
),
[]
[]
)
)
...
@@ -250,3 +251,12 @@ class OneToOneRegressionTests(TestCase):
...
@@ -250,3 +251,12 @@ class OneToOneRegressionTests(TestCase):
self
.
p1
.
delete
()
self
.
p1
.
delete
()
self
.
assertTrue
(
UndergroundBar
.
objects
.
filter
(
pk
=
u
.
pk
)
.
exists
())
self
.
assertTrue
(
UndergroundBar
.
objects
.
filter
(
pk
=
u
.
pk
)
.
exists
())
self
.
assertIsNone
(
UndergroundBar
.
objects
.
get
(
pk
=
u
.
pk
)
.
place
)
self
.
assertIsNone
(
UndergroundBar
.
objects
.
get
(
pk
=
u
.
pk
)
.
place
)
def
test_hidden_accessor
(
self
):
"""
When a '+' ending related name is specified no reverse accessor should
be added to the related model.
"""
self
.
assertFalse
(
hasattr
(
Target
,
HiddenPointer
.
_meta
.
get_field
(
'target'
)
.
related
.
get_accessor_name
())
)
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