Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #10799: fixed the use of list_editable with model inheritance a…

…nd custom one-to-one parent links. Thanks, Alex Gaynor.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10590 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ccc8e104eef01752f078bedc99ca6b756e1f048c 1 parent 1e4ad6f
@jacobian jacobian authored
View
5 django/forms/models.py
@@ -470,7 +470,10 @@ def add_fields(self, form, index):
# data back. Generally, pk.editable should be false, but for some
# reason, auto_created pk fields and AutoField's editable attribute is
# True, so check for that as well.
- if (not pk.editable) or (pk.auto_created or isinstance(pk, AutoField)):
+ def pk_is_editable(pk):
+ return ((not pk.editable) or (pk.auto_created or isinstance(pk, AutoField))
+ or (pk.rel and pk.rel.parent_link and pk_is_editable(pk.rel.to._meta.pk)))
+ if pk_is_editable(pk):
try:
pk_value = self.get_queryset()[index].pk
except IndexError:
View
9 tests/modeltests/model_formsets/models.py
@@ -108,6 +108,10 @@ class Meta:
class MexicanRestaurant(Restaurant):
serves_tacos = models.BooleanField()
+class ClassyMexicanRestaurant(MexicanRestaurant):
+ restaurant = models.OneToOneField(MexicanRestaurant, parent_link=True, primary_key=True)
+ tacos_are_yummy = models.BooleanField()
+
# models for testing unique_together validation when a fk is involved and
# using inlineformset_factory.
class Repository(models.Model):
@@ -934,4 +938,9 @@ def __unicode__(self):
>>> formset.get_queryset()
[<Player: Bobby>]
+# a formset for a Model that has a custom primary key that still needs to be
+# added to the formset automatically
+>>> FormSet = modelformset_factory(ClassyMexicanRestaurant, fields=["tacos_are_yummy"])
+>>> sorted(FormSet().forms[0].fields.keys())
+['restaurant', 'tacos_are_yummy']
"""}
View
11 tests/regressiontests/admin_views/models.py
@@ -269,6 +269,16 @@ class PodcastAdmin(admin.ModelAdmin):
ordering = ('name',)
+class Vodcast(Media):
+ media = models.OneToOneField(Media, primary_key=True, parent_link=True)
+ released = models.BooleanField(default=False)
+
+class VodcastAdmin(admin.ModelAdmin):
+ list_display = ('name', 'released')
+ list_editable = ('released',)
+
+ ordering = ('name',)
+
class Parent(models.Model):
name = models.CharField(max_length=128)
@@ -327,6 +337,7 @@ class PictureAdmin(admin.ModelAdmin):
admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)
admin.site.register(OldSubscriber, OldSubscriberAdmin)
admin.site.register(Podcast, PodcastAdmin)
+admin.site.register(Vodcast, VodcastAdmin)
admin.site.register(Parent, ParentAdmin)
admin.site.register(EmptyModel, EmptyModelAdmin)
admin.site.register(Fabric, FabricAdmin)
View
9 tests/regressiontests/admin_views/tests.py
@@ -2,8 +2,6 @@
import re
import datetime
-import os
-
from django.core.files import temp as tempfile
from django.test import TestCase
from django.contrib.auth.models import User, Permission
@@ -18,7 +16,7 @@
from models import (Article, BarAccount, CustomArticle, EmptyModel,
ExternalSubscriber, FooAccount, Gallery,
ModelWithStringPrimaryKey, Person, Persona, Picture,
- Podcast, Section, Subscriber)
+ Podcast, Section, Subscriber, Vodcast)
try:
set
@@ -801,6 +799,11 @@ def test_inheritance(self):
response = self.client.get('/test_admin/admin/admin_views/podcast/')
self.failUnlessEqual(response.status_code, 200)
+ def test_inheritance_2(self):
+ Vodcast.objects.create(name="This Week in Django", released=True)
+ response = self.client.get('/test_admin/admin/admin_views/vodcast/')
+ self.failUnlessEqual(response.status_code, 200)
+
def test_changelist_input_html(self):
response = self.client.get('/test_admin/admin/admin_views/person/')
# 2 inputs per object(the field and the hidden id field) = 6
Please sign in to comment.
Something went wrong with that request. Please try again.