Python django.contrib.admin.StackedInline() Examples

The following are 5 code examples of django.contrib.admin.StackedInline(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.contrib.admin , or try the search function .
Example #1
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 8 votes vote down vote up
def test_exclude_inline_model_admin(self):
        """
        Regression test for #9932 - exclude in InlineModelAdmin should not
        contain the ForeignKey field used in ModelAdmin.model
        """
        class SongInline(admin.StackedInline):
            model = Song
            exclude = ['album']

        class AlbumAdmin(admin.ModelAdmin):
            model = Album
            inlines = [SongInline]

        errors = AlbumAdmin(Album, AdminSite()).check()
        expected = [
            checks.Error(
                "Cannot exclude the field 'album', because it is the foreign key "
                "to the parent model 'admin_checks.Album'.",
                obj=SongInline,
                id='admin.E201',
            )
        ]
        self.assertEqual(errors, expected) 
Example #2
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_exclude_inline_model_admin(self):
        """
        Regression test for #9932 - exclude in InlineModelAdmin should not
        contain the ForeignKey field used in ModelAdmin.model
        """
        class SongInline(admin.StackedInline):
            model = Song
            exclude = ['album']

        class AlbumAdmin(admin.ModelAdmin):
            model = Album
            inlines = [SongInline]

        errors = AlbumAdmin(Album, AdminSite()).check()
        expected = [
            checks.Error(
                "Cannot exclude the field 'album', because it is the foreign key "
                "to the parent model 'admin_checks.Album'.",
                obj=SongInline,
                id='admin.E201',
            )
        ]
        self.assertEqual(errors, expected) 
Example #3
Source File: admin.py    From prospector with GNU General Public License v3.0 5 votes vote down vote up
def make_inline(model_, extra_=0):
    class Inline(admin.StackedInline):
        model = model_
        extra = extra_

    return Inline 
Example #4
Source File: test_admin.py    From django-localized-fields with MIT License 5 votes vote down vote up
def test_stackedmodel_admin(cls):
        """Tests whether :see:LocalizedFieldsAdminMixin mixin are works with
        admin.StackedInline."""

        class TestModelStackedInline(
            LocalizedFieldsAdminMixin, admin.StackedInline
        ):
            model = cls.TestModel

        @admin.register(cls.TestRelModel)
        class TestRelModelAdmin(admin.ModelAdmin):
            inlines = [TestModelStackedInline]

        assert len(check_admin_app(apps.get_app_configs())) == 0 
Example #5
Source File: admin.py    From openwisp-controller with GNU General Public License v3.0 5 votes vote down vote up
def get_queryset(self, request):
        """
        Override MultitenantAdminMixin.get_queryset() because it breaks
        """
        return super(admin.StackedInline, self).get_queryset(request)