コード例 #1
0
ファイル: reset.py プロジェクト: celalp/django-jazzmin
    def handle(self, *args, **options):
        call_command("reset_db", "--noinput")
        call_command("migrate")

        library = LibraryFactory()
        UserFactory(username="******",
                    email="*****@*****.**",
                    password="******",
                    is_superuser=True)

        users = UserFactory.create_batch(2, is_staff=False)

        GroupFactory.create_batch(5)

        for author in AuthorFactory.create_batch(10):
            for book in BookFactory.create_batch(5,
                                                 author=author,
                                                 library=library):
                BookLoanFactory(book=book, borrower=choice(users))

        self.stdout.write("All Data reset")
コード例 #2
0
def generate_objects():
    print("Creating books...")
    BookFactory.create_batch(size=10)
    print("Done.")
コード例 #3
0
def test_list(admin_client):
    """
    We can render the list view
    """
    BookFactory.create_batch(5)

    url = reverse("admin:books_book_changelist")

    response = admin_client.get(url)
    templates_used = [t.name for t in response.templates]

    assert response.status_code == 200
    render_counts = {x: templates_used.count(x) for x in set(templates_used)}

    # The number of times each template was rendered
    assert render_counts == {
        "admin/filter.html": 2,
        "admin/base.html": 1,
        "admin/base_site.html": 1,
        "admin/date_hierarchy.html": 1,
        "admin/change_list_object_tools.html": 1,
        "admin/change_list.html": 1,
        "admin/change_list_results.html": 1,
        "admin/pagination.html": 1,
        "admin/search_form.html": 1,
        "admin/actions.html": 2,
        "admin/import_export/change_list.html": 1,
        "admin/import_export/change_list_export_item.html": 1,
        "admin/import_export/change_list_import_export.html": 1,
        "admin/import_export/change_list_import_item.html": 1,
        "django/forms/widgets/checkbox.html": 5,
        "django/forms/widgets/text.html": 5,
        "django/forms/widgets/select_option.html": 4,
        "django/forms/widgets/select.html": 2,
        "django/forms/widgets/input.html": 21,
        "django/forms/widgets/hidden.html": 11,
        "django/forms/widgets/attrs.html": 27,
        "jazzmin/includes/ui_builder_panel.html": 1,
    }

    # The templates that were used
    assert set(templates_used) == {
        "admin/filter.html",
        "admin/base.html",
        "admin/base_site.html",
        "admin/date_hierarchy.html",
        "admin/change_list_object_tools.html",
        "admin/change_list.html",
        "admin/change_list_results.html",
        "admin/pagination.html",
        "admin/search_form.html",
        "admin/actions.html",
        "admin/import_export/change_list.html",
        "admin/import_export/change_list_export_item.html",
        "admin/import_export/change_list_import_export.html",
        "admin/import_export/change_list_import_item.html",
        "django/forms/widgets/checkbox.html",
        "django/forms/widgets/text.html",
        "django/forms/widgets/select_option.html",
        "django/forms/widgets/select.html",
        "django/forms/widgets/input.html",
        "django/forms/widgets/hidden.html",
        "django/forms/widgets/attrs.html",
        "jazzmin/includes/ui_builder_panel.html",
    }