mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #13696 -- ensured inline pk field is rendered
This commit is contained in:
parent
415a36947c
commit
3aad955ea8
6 changed files with 64 additions and 6 deletions
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue