Opened 6 years ago

Last modified 6 years ago

#26060 closed Bug

Regression in reverse one-to-one field when in readonly_fields — at Initial Version

Reported by: Steven Davidson Owned by: nobody
Component: contrib.admin Version: 1.8
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When upgrading from 1.7 to 1.8(.8) I started encountering errors in the admin with a reverse one to one relationship when it was in readonly_fields. I assume this is a regression. Naturally, I am happy to help fix it (if it is not by design), given a steer!

Tested with Python 2.7.10, the project template was created with Django 1.8.8.

cd /tmp
git clone
cd django-readonly-onetoone/
mkvirtualenv dj_onetoone

# make sure virtualenv is activated, then:
pip install -r requirements.txt
./ migrate
./ createsuperuser
./ runserver
# open
# create an A object
# create a B object referencing the A
# return to original A object

# now upgrade to Django 1.8.8
pip install Django==1.8.8
./ migrate
./ runserver
# return to
AttributeError at /admin/simple/a/1/
OneToOneRel object has no attribute 'rel

# now upgrade to Django 1.9.1
pip install Django==1.9.1
./ migrate
./ runserver
# go to
AttributeError at /admin/simple/a/1/change/
'OneToOneRel' object has no attribute 'flatchoices

A simple workaround is to use a method on ModelAdmin

class WorkingAAdmin(admin.ModelAdmin):
    readonly_fields = ['working_b']
    def working_b(self, instance):
        return instance.b
    working_b.short_description = 'working'

See also

Change History (1)

Changed 6 years ago by Steven Davidson

Zip of Github project

Note: See TracTickets for help on using tickets.
Back to Top