Skip to content

Commit

Permalink
Fixed #28898 -- Corrected admin check to allow a OneToOneField in Mod…
Browse files Browse the repository at this point in the history
…elAdmin.autocomplete_fields.
  • Loading branch information
fenrrir authored and timgraham committed Dec 13, 2017
1 parent f9a0766 commit 30a389b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ answer newbie questions, and generally made Django that much better:
Robert Wittams
Rob Hudson <http://rob.cogit8.org/>
Robin Munn <http://www.geekforgod.com/>
Rodrigo Pinheiro Marques de Araújo <[email protected]>
Romain Garrigues <[email protected]>
Ronny Haryanto <http://ronny.haryan.to/>
Ross Poulton <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/admin/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _check_autocomplete_fields_item(self, obj, model, field_name, label):
except FieldDoesNotExist:
return refer_to_missing_field(field=field_name, option=label, model=model, obj=obj, id='admin.E037')
else:
if not (field.many_to_many or field.many_to_one):
if not field.many_to_many and not isinstance(field, models.ForeignKey):
return must_be(
'a foreign key or a many-to-many field',
option=label, obj=obj, id='admin.E038'
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/2.0.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ Bugfixes
(:ticket:`28856`).

* Reallowed filtering a queryset with ``GeometryField=None`` (:ticket:`28896`).

* Corrected admin check to allow a ``OneToOneField`` in
``ModelAdmin.autocomplete_fields`` (:ticket:`28898`).
15 changes: 14 additions & 1 deletion tests/modeladmin/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from django.forms.models import BaseModelFormSet
from django.test import SimpleTestCase

from .models import Band, Song, ValidationTestInlineModel, ValidationTestModel
from .models import (
Band, Song, User, ValidationTestInlineModel, ValidationTestModel,
)


class CheckTestCase(SimpleTestCase):
Expand Down Expand Up @@ -1243,3 +1245,14 @@ class AutocompleteAdmin(ModelAdmin):
site = AdminSite()
site.register(Band, SearchFieldsAdmin)
self.assertIsValid(AutocompleteAdmin, Song, admin_site=site)

def test_autocomplete_is_onetoone(self):
class UserAdmin(ModelAdmin):
search_fields = ('name', )

class Admin(ModelAdmin):
autocomplete_fields = ('best_friend', )

site = AdminSite()
site.register(User, UserAdmin)
self.assertIsValid(Admin, ValidationTestModel, admin_site=site)

0 comments on commit 30a389b

Please sign in to comment.