[Django] #37168: Readonly fields with db_default display DatabaseDefault representation

6 views
Skip to first unread message

Django

unread,
Jun 13, 2026, 6:50:18 AM (23 hours ago) Jun 13
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
Reporter: Mariusz | Owner: Mariusz Felisiak
Felisiak |
Type: Bug | Status: assigned
Component: Forms | Version: 6.0
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Readonly fields with `db_default` display `DatabaseDefault()`
representation in the admin. For example:

- `models.py`
{{{#!python
class MyModel(models.Model):
uuid = models.UUIDField(db_default=UUID7(), editable=False,
primary_key=True)
created_datetime = models.DateTimeField(db_default=Now(),
editable=False)
modified_datetime = models.DateTimeField(db_default=Now(),
editable=False)
name = models.TextField()
}}}

- `admin.py`

{{{#!python
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
readonly_fields = ["uuid", "created_datetime", "modified_datetime"]
}}}


I think they should be consider as any other empty values.
--
Ticket URL: <https://code.djangoproject.com/ticket/37168>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 13, 2026, 6:51:29 AM (23 hours ago) Jun 13
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Forms | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* Attachment "Screenshot_20260613_125111.png" added.

Django

unread,
Jun 13, 2026, 6:52:29 AM (23 hours ago) Jun 13
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Forms | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Mariusz Felisiak:

Old description:

> Readonly fields with `db_default` display `DatabaseDefault()`
> representation in the admin. For example:
>
> - `models.py`
> {{{#!python
> class MyModel(models.Model):
> uuid = models.UUIDField(db_default=UUID7(), editable=False,
> primary_key=True)
> created_datetime = models.DateTimeField(db_default=Now(),
> editable=False)
> modified_datetime = models.DateTimeField(db_default=Now(),
> editable=False)
> name = models.TextField()
> }}}
>
> - `admin.py`
>
> {{{#!python
> @admin.register(MyModel)
> class MyModelAdmin(admin.ModelAdmin):
> readonly_fields = ["uuid", "created_datetime", "modified_datetime"]
> }}}
>

> I think they should be consider as any other empty values.

New description:

Readonly fields with `db_default` display `DatabaseDefault()`
representation in the admin. For example:

- `models.py`
{{{#!python
class MyModel(models.Model):
uuid = models.UUIDField(db_default=UUID7(), editable=False,
primary_key=True)
created_datetime = models.DateTimeField(db_default=Now(),
editable=False)
modified_datetime = models.DateTimeField(db_default=Now(),
editable=False)
name = models.TextField()
}}}

- `admin.py`

{{{#!python
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
readonly_fields = ["uuid", "created_datetime", "modified_datetime"]
}}}

[[Image(Screenshot_20260613_125111.png​)]]
I think they should be consider as any other empty values.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/37168#comment:1>

Django

unread,
Jun 13, 2026, 12:06:41 PM (17 hours ago) Jun 13
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Forms | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mariusz Felisiak):

We wanted to add `DatabaseDefault()` to the list of `Field.empty_values`
and modify its `__hash__` and `__eq__`. Unfortunately, there is an issue
in importing `DatabaseDefault` anywhere in the `forms` module and
`expression` is required to initialize `DatabaseDefault`. I'm thinking
about adding `is_value_empty()` hook to the `Field`:
{{{#!python
def is_value_empty(self, value):
return value in self.empty_values or isinstance(value,
DatabaseDefault):
}}}
and reusing it everywhere we currently check `if value in
self.empty_values`.
--
Ticket URL: <https://code.djangoproject.com/ticket/37168#comment:2>

Django

unread,
Jun 13, 2026, 1:59:09 PM (15 hours ago) Jun 13
to django-...@googlegroups.com
#37168: Readonly fields with db_default display DatabaseDefault representation
-------------------------------------+-------------------------------------
Reporter: Mariusz Felisiak | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Forms | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* Attachment "ticket_37168.zip" added.
Reply all
Reply to author
Forward
0 new messages