Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions django/contrib/admin/templates/admin/change_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ <h2 id="changelist-filter-header">{% translate 'Filter' %}</h2>
{% if action_form and actions_on_bottom and cl.show_admin_actions %}{% admin_actions %}{% endif %}
{% endblock %}
{% block pagination %}
<div class="changelist-footer">
{% pagination cl %}
{% if cl.formset and cl.result_count %}<input type="submit" name="_save" class="default" value="{% translate 'Save' %}">{% endif %}
<div class="changelist-footer">
{% pagination cl %}
{% if cl.formset and cl.result_count %}<input type="submit" name="_save" class="default" value="{% translate 'Save' %}">{% endif %}
</div>
{% endblock %}
</div>
</form>
</div>
</div>
Expand Down
7 changes: 2 additions & 5 deletions django/core/files/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def __str__(self):
return self.name or ""

def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self or "None")
return "<%s: %s>" % (self.__class__.__name__, self.name or "None")

def __bool__(self):
return bool(self.name)
return True

def __len__(self):
return self.size
Expand Down Expand Up @@ -134,9 +134,6 @@ def __init__(self, content, name=None):
def __str__(self):
return "Raw content"

def __bool__(self):
return True

def open(self, mode=None):
self.seek(0)
return self
Expand Down
3 changes: 3 additions & 0 deletions django/core/files/uploadedfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def __init__(
def __repr__(self):
return "<%s: %s (%s)>" % (self.__class__.__name__, self.name, self.content_type)

def __bool__(self):
return bool(self.name)

def _get_name(self):
return self._name

Expand Down
3 changes: 3 additions & 0 deletions django/db/models/fields/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def __eq__(self, other):
def __hash__(self):
return hash(self.name)

def __bool__(self):
return bool(self.name)

# The standard File contains most of the necessary properties, but
# FieldFiles can be instantiated without a name, so that needs to
# be checked for here.
Expand Down
5 changes: 4 additions & 1 deletion docs/releases/6.0.5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ Django 6.0.5 fixes several bugs in 6.0.4.
Bugfixes
========

* ...
* Fixed a misplaced ``</div>`` in the
``django/contrib/admin/templates/admin/change_list.html`` template added in
Django 6.0 that could be problematic when overriding the ``pagination`` block
(:ticket:`37029`).
7 changes: 7 additions & 0 deletions docs/releases/6.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,13 @@ Miscellaneous
primary key when a ``QuerySet``'s ordering has been forcibly cleared by
calling :meth:`~.QuerySet.order_by` with no arguments.

* The :class:`~django.core.files.File` class now always evaluates to ``True``
in boolean contexts, rather than relying on the ``name`` attribute. The
built-in subclasses ``FieldFile``, ``UploadedFile``,
``TemporaryUploadedFile``, ``InMemoryUploadedFile``, and
``SimpleUploadedFile`` retain the previous behavior of evaluating based on
the ``name`` attribute.

.. _deprecated-features-6.1:

Features deprecated in 6.1
Expand Down
3 changes: 3 additions & 0 deletions tests/files/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ def test_noname_file_default_name(self):
def test_noname_file_get_size(self):
self.assertEqual(File(BytesIO(b"A file with no name")).size, 19)

def test_noname_bool(self):
self.assertTrue(bool(File(BytesIO(b"A file with no name"))))


class ContentFileTestCase(unittest.TestCase):
def test_content_file_default_name(self):
Expand Down
Loading