Ticket #10799: list-editable.diff

File list-editable.diff, 6.5 KB (added by Alex Gaynor, 15 years ago)
  • django/db/models/fields/related.py

    diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
    index f2723a1..0ff0ff2 100644
    a b class ManyToManyField(RelatedField, Field):  
    955955        # A ManyToManyField is not represented by a single column,
    956956        # so return None.
    957957        return None
    958 
  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index 010d3bf..fa77611 100644
    a b class BaseModelFormSet(BaseFormSet):  
    469469        # data back. Generally, pk.editable should be false, but for some
    470470        # reason, auto_created pk fields and AutoField's editable attribute is
    471471        # True, so check for that as well.
    472         if (not pk.editable) or (pk.auto_created or isinstance(pk, AutoField)):
     472        def pk_is_editable(pk):
     473            return ((not pk.editable) or (pk.auto_created or isinstance(pk, AutoField))
     474                or (pk.rel and pk.rel.parent_link and pk_is_editable(pk.rel.to._meta.pk)))
     475        if pk_is_editable(pk):
    473476            try:
    474477                pk_value = self.get_queryset()[index].pk
    475478            except IndexError:
  • tests/modeltests/model_formsets/models.py

    diff --git a/tests/modeltests/model_formsets/models.py b/tests/modeltests/model_formsets/models.py
    index d8cbe34..718c73a 100644
    a b class CustomPrimaryKey(models.Model):  
    5858class Place(models.Model):
    5959    name = models.CharField(max_length=50)
    6060    city = models.CharField(max_length=50)
    61    
     61
    6262    def __unicode__(self):
    6363        return self.name
    6464
    class OwnerProfile(models.Model):  
    8585
    8686class Restaurant(Place):
    8787    serves_pizza = models.BooleanField()
    88    
     88
    8989    def __unicode__(self):
    9090        return self.name
    9191
    class Price(models.Model):  
    108108class MexicanRestaurant(Restaurant):
    109109    serves_tacos = models.BooleanField()
    110110
     111class ClassyMexicanRestaurant(MexicanRestaurant):
     112    restaurant = models.OneToOneField(MexicanRestaurant, parent_link=True, primary_key=True)
     113    tacos_are_yummy = models.BooleanField()
     114
    111115# models for testing unique_together validation when a fk is involved and
    112116# using inlineformset_factory.
    113117class Repository(models.Model):
    True  
    569573...     print book.title
    570574Les Fleurs du Mal
    571575
    572 Test inline formsets where the inline-edited object uses multi-table inheritance, thus 
     576Test inline formsets where the inline-edited object uses multi-table inheritance, thus
    573577has a non AutoField yet auto-created primary key.
    574578
    575579>>> AuthorBooksFormSet3 = inlineformset_factory(Author, AlternateBook, can_delete=False, extra=1)
    True  
    736740>>> formset.save()
    737741[<OwnerProfile: Joe Perry is 55>]
    738742
    739 # ForeignKey with unique=True should enforce max_num=1 
     743# ForeignKey with unique=True should enforce max_num=1
    740744
    741745>>> FormSet = inlineformset_factory(Place, Location, can_delete=False)
    742746>>> formset = FormSet(instance=place)
    True  
    934938>>> formset.get_queryset()
    935939[<Player: Bobby>]
    936940
     941# a formset for a Model that has a custom primary key that still needs to be
     942# added to the formset automatically
     943>>> FormSet = modelformset_factory(ClassyMexicanRestaurant, fields=["tacos_are_yummy"])
     944>>> sorted(FormSet().forms[0].fields.keys())
     945['restaurant', 'tacos_are_yummy']
    937946"""}
  • tests/regressiontests/admin_views/models.py

    diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
    index f1c24c2..906c271 100644
    a b class PodcastAdmin(admin.ModelAdmin):  
    266266
    267267    ordering = ('name',)
    268268
     269class Vodcast(Media):
     270    media = models.OneToOneField(Media, primary_key=True, parent_link=True)
     271    released = models.BooleanField(default=False)
     272
     273class VodcastAdmin(admin.ModelAdmin):
     274    list_display = ('name', 'released')
     275    list_editable = ('released',)
     276
     277    ordering = ('name',)
     278
    269279class Parent(models.Model):
    270280    name = models.CharField(max_length=128)
    271281
    admin.site.register(Subscriber, SubscriberAdmin)  
    303313admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)
    304314admin.site.register(OldSubscriber, OldSubscriberAdmin)
    305315admin.site.register(Podcast, PodcastAdmin)
     316admin.site.register(Vodcast, VodcastAdmin)
    306317admin.site.register(Parent, ParentAdmin)
    307318admin.site.register(EmptyModel, EmptyModelAdmin)
    308319admin.site.register(Fabric, FabricAdmin)
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index d7bce8f..76efdc3 100644
    a b from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME  
    1313from django.utils.html import escape
    1414
    1515# local test models
    16 from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber, Podcast, EmptyModel
     16from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber, Vodcast, Podcast, EmptyModel
    1717
    1818try:
    1919    set
    class AdminViewListEditable(TestCase):  
    796796        response = self.client.get('/test_admin/admin/admin_views/podcast/')
    797797        self.failUnlessEqual(response.status_code, 200)
    798798
     799    def test_inheritance_2(self):
     800        Vodcast.objects.create(name="This Week in Django", released=True)
     801        response = self.client.get('/test_admin/admin/admin_views/vodcast/')
     802        self.failUnlessEqual(response.status_code, 200)
     803
    799804    def test_changelist_input_html(self):
    800805        response = self.client.get('/test_admin/admin/admin_views/person/')
    801806        # 2 inputs per object(the field and the hidden id field) = 6
    class AdminActionsTest(TestCase):  
    9951000        }
    9961001        response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
    9971002        self.failUnlessEqual(response.status_code, 302)
    998        
     1003
    9991004    def test_model_without_action(self):
    10001005        "Tests a ModelAdmin without any action"
    10011006        response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/')
    class AdminActionsTest(TestCase):  
    10041009            '<input type="checkbox" class="action-select"' not in response.content,
    10051010            "Found an unexpected action toggle checkboxbox in response"
    10061011        )
    1007        
     1012
    10081013    def test_multiple_actions_form(self):
    10091014        """
    10101015        Test that actions come from the form whose submit button was pressed (#10618).
Back to Top