Ticket #30153: test.2.patch

File test.2.patch, 3.0 KB (added by Matthias Kestenholz, 6 years ago)
  • tests/admin_inlines/admin.py

    diff --git a/tests/admin_inlines/admin.py b/tests/admin_inlines/admin.py
    index b5f343a55b..d53bdc06a3 100644
    a b site.register(Holder, HolderAdmin, inlines=[InnerInline])  
    242242# ModelAdmin and Inline media
    243243site.register(Holder2, HolderAdmin, inlines=[InnerInline2, InnerInline2Tabular])
    244244# only Inline media
    245 site.register(Holder3, inlines=[InnerInline3])
     245site.register(Holder3, inlines=[InnerInline3], filter_horizontal=['categories'])
    246246
    247247site.register(Poll, PollAdmin)
    248248site.register(Novel, NovelAdmin)
  • tests/admin_inlines/models.py

    diff --git a/tests/admin_inlines/models.py b/tests/admin_inlines/models.py
    index 38b2999f79..019470a147 100644
    a b Testing of admin inline formsets.  
    33"""
    44import random
    55
     6from django import forms
    67from django.contrib.contenttypes.fields import GenericForeignKey
    78from django.contrib.contenttypes.models import ContentType
    89from django.db import models
    class Inner2(models.Model):  
    8889    holder = models.ForeignKey(Holder2, models.CASCADE)
    8990
    9091
     92class CustomNumberInput(forms.NumberInput):
     93    class Media:
     94        js = ("custom_number.js",)
     95
     96
     97class CustomIntegerField(models.IntegerField):
     98    def formfield(self, **kwargs):
     99        kwargs["widget"] = CustomNumberInput
     100        return super().formfield(**kwargs)
     101
     102
     103class Holder3Category(models.Model):
     104    title = models.CharField(max_length=100)
     105
     106
    91107class Holder3(models.Model):
    92     dummy = models.IntegerField()
     108    # The ordering of those two fields is important.
     109    # https://code.djangoproject.com/ticket/30153
     110    dummy = CustomIntegerField()
     111    categories = models.ManyToManyField(Holder3Category, blank=True)
    93112
    94113
    95114class Inner3(models.Model):
    96     dummy = models.IntegerField()
     115    dummy = CustomIntegerField()
    97116    holder = models.ForeignKey(Holder3, models.CASCADE)
    98117
    99118# Models for ticket #8190
  • tests/admin_inlines/tests.py

    diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py
    index 0a1ab5acbb..21ea2ac968 100644
    a b class TestInlineMedia(TestDataMixin, TestCase):  
    505505        )
    506506        self.assertContains(response, 'my_awesome_inline_scripts.js')
    507507
     508        self.assertEqual(
     509            response.context["media"]._js,
     510            [
     511                'admin/js/vendor/jquery/jquery.min.js',
     512                'admin/js/jquery.init.js',
     513                'admin/js/core.js',
     514                'admin/js/admin/RelatedObjectLookups.js',
     515                'admin/js/actions.min.js',
     516                'admin/js/urlify.js',
     517                'admin/js/prepopulate.min.js',
     518                'admin/js/vendor/xregexp/xregexp.min.js',
     519                'admin/js/inlines.min.js',
     520                'my_awesome_inline_scripts.js',
     521                'custom_number.js',
     522            ],
     523        )
     524
    508525    def test_all_inline_media(self):
    509526        holder = Holder2(dummy=13)
    510527        holder.save()
Back to Top