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
3aad955e
Kaydet (Commit)
3aad955e
authored
Tem 19, 2013
tarafından
Karen Tracey
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #13696 -- ensured inline pk field is rendered
üst
415a3694
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
6 deletions
+64
-6
helpers.py
django/contrib/admin/helpers.py
+5
-3
stacked.html
...go/contrib/admin/templates/admin/edit_inline/stacked.html
+1
-1
tabular.html
...go/contrib/admin/templates/admin/edit_inline/tabular.html
+1
-1
admin.py
tests/admin_inlines/admin.py
+19
-1
models.py
tests/admin_inlines/models.py
+20
-0
tests.py
tests/admin_inlines/tests.py
+18
-0
No files found.
django/contrib/admin/helpers.py
Dosyayı görüntüle @
3aad955e
...
...
@@ -266,10 +266,12 @@ class InlineAdminForm(AdminForm):
yield
InlineFieldset
(
self
.
formset
,
self
.
form
,
name
,
self
.
readonly_fields
,
model_admin
=
self
.
model_admin
,
**
options
)
def
has_auto_field
(
self
):
if
self
.
form
.
_meta
.
model
.
_meta
.
has_auto_field
:
def
needs_explicit_pk_field
(
self
):
# Auto fields are editable (oddly), so need to check for auto or non-editable pk
if
self
.
form
.
_meta
.
model
.
_meta
.
has_auto_field
or
not
self
.
form
.
_meta
.
model
.
_meta
.
pk
.
editable
:
return
True
# Also search any parents for an auto field.
# Also search any parents for an auto field. (The pk info is propagated to child
# models so that does not need to be checked in parents.)
for
parent
in
self
.
form
.
_meta
.
model
.
_meta
.
get_parent_list
():
if
parent
.
_meta
.
has_auto_field
:
return
True
...
...
django/contrib/admin/templates/admin/edit_inline/stacked.html
Dosyayı görüntüle @
3aad955e
...
...
@@ -13,7 +13,7 @@
{% for fieldset in inline_admin_form %}
{% include "admin/includes/fieldset.html" %}
{% endfor %}
{% if inline_admin_form.
has_auto
_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
{% if inline_admin_form.
needs_explicit_pk
_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
{{ inline_admin_form.fk_field.field }}
</div>
{% endfor %}
</div>
...
...
django/contrib/admin/templates/admin/edit_inline/tabular.html
Dosyayı görüntüle @
3aad955e
...
...
@@ -29,7 +29,7 @@
{% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
{% if inline_admin_form.show_url %}
<a
href=
"{% url 'admin:view_on_site' inline_admin_form.original_content_type_id inline_admin_form.original.pk %}"
>
{% trans "View on site" %}
</a>
{% endif %}
</p>
{% endif %}
{% if inline_admin_form.
has_auto
_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
{% if inline_admin_form.
needs_explicit_pk
_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
{{ inline_admin_form.fk_field.field }}
{% spaceless %}
{% for fieldset in inline_admin_form %}
...
...
tests/admin_inlines/admin.py
Dosyayı görüntüle @
3aad955e
...
...
@@ -12,8 +12,26 @@ class BookInline(admin.TabularInline):
model
=
Author
.
books
.
through
class
NonAutoPKBookTabularInline
(
admin
.
TabularInline
):
model
=
NonAutoPKBook
class
NonAutoPKBookStackedInline
(
admin
.
StackedInline
):
model
=
NonAutoPKBook
class
EditablePKBookTabularInline
(
admin
.
TabularInline
):
model
=
EditablePKBook
class
EditablePKBookStackedInline
(
admin
.
StackedInline
):
model
=
EditablePKBook
class
AuthorAdmin
(
admin
.
ModelAdmin
):
inlines
=
[
BookInline
]
inlines
=
[
BookInline
,
NonAutoPKBookTabularInline
,
NonAutoPKBookStackedInline
,
EditablePKBookTabularInline
,
EditablePKBookStackedInline
]
class
InnerInline
(
admin
.
StackedInline
):
...
...
tests/admin_inlines/models.py
Dosyayı görüntüle @
3aad955e
...
...
@@ -3,6 +3,7 @@ Testing of admin inline formsets.
"""
from
__future__
import
unicode_literals
import
random
from
django.db
import
models
from
django.contrib.contenttypes.models
import
ContentType
...
...
@@ -48,6 +49,25 @@ class Author(models.Model):
books
=
models
.
ManyToManyField
(
Book
)
class
NonAutoPKBook
(
models
.
Model
):
rand_pk
=
models
.
IntegerField
(
primary_key
=
True
,
editable
=
False
)
author
=
models
.
ForeignKey
(
Author
)
title
=
models
.
CharField
(
max_length
=
50
)
def
save
(
self
,
*
args
,
**
kwargs
):
while
not
self
.
rand_pk
:
test_pk
=
random
.
randint
(
1
,
99999
)
if
not
NonAutoPKBook
.
objects
.
filter
(
rand_pk
=
test_pk
)
.
exists
():
self
.
rand_pk
=
test_pk
super
(
NonAutoPKBook
,
self
)
.
save
(
*
args
,
**
kwargs
)
class
EditablePKBook
(
models
.
Model
):
manual_pk
=
models
.
IntegerField
(
primary_key
=
True
)
author
=
models
.
ForeignKey
(
Author
)
title
=
models
.
CharField
(
max_length
=
50
)
class
Holder
(
models
.
Model
):
dummy
=
models
.
IntegerField
()
...
...
tests/admin_inlines/tests.py
Dosyayı görüntüle @
3aad955e
...
...
@@ -211,6 +211,24 @@ class TestInline(TestCase):
self
.
assertContains
(
response
,
max_forms_input
%
2
)
self
.
assertContains
(
response
,
total_forms_hidden
)
def
test_inline_nonauto_noneditable_pk
(
self
):
response
=
self
.
client
.
get
(
'/admin/admin_inlines/author/add/'
)
self
.
assertContains
(
response
,
'<input id="id_nonautopkbook_set-0-rand_pk" name="nonautopkbook_set-0-rand_pk" type="hidden" />'
,
html
=
True
)
self
.
assertContains
(
response
,
'<input id="id_nonautopkbook_set-2-0-rand_pk" name="nonautopkbook_set-2-0-rand_pk" type="hidden" />'
,
html
=
True
)
def
test_inline_editable_pk
(
self
):
response
=
self
.
client
.
get
(
'/admin/admin_inlines/author/add/'
)
self
.
assertContains
(
response
,
'<input class="vIntegerField" id="id_editablepkbook_set-0-manual_pk" name="editablepkbook_set-0-manual_pk" type="text" />'
,
html
=
True
,
count
=
1
)
self
.
assertContains
(
response
,
'<input class="vIntegerField" id="id_editablepkbook_set-2-0-manual_pk" name="editablepkbook_set-2-0-manual_pk" type="text" />'
,
html
=
True
,
count
=
1
)
@override_settings
(
PASSWORD_HASHERS
=
(
'django.contrib.auth.hashers.SHA1PasswordHasher'
,))
class
TestInlineMedia
(
TestCase
):
...
...
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