Ticket #28898: admin-autocomplete-onetoone.patch

File admin-autocomplete-onetoone.patch, 3.2 KB (added by Rodrigo Pinheiro Marques de Araújo, 7 years ago)

Patch - first version

  • AUTHORS

    diff --git a/AUTHORS b/AUTHORS
    index df5bbb82ab..a46cf625cb 100644
    a b answer newbie questions, and generally made Django that much better:  
    689689    Robert Wittams
    690690    Rob Hudson <http://rob.cogit8.org/>
    691691    Robin Munn <http://www.geekforgod.com/>
     692    Rodrigo Pinheiro Marques de Araújo <fenrrir@gmail.com>
    692693    Romain Garrigues <romain.garrigues.cs@gmail.com>
    693694    Ronny Haryanto <http://ronny.haryan.to/>
    694695    Ross Poulton <ross@rossp.org>
  • django/contrib/admin/checks.py

    diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
    index c8e05bde7c..96194f7c74 100644
    a b class BaseModelAdminChecks:  
    104104        except FieldDoesNotExist:
    105105            return refer_to_missing_field(field=field_name, option=label, model=model, obj=obj, id='admin.E037')
    106106        else:
    107             if not (field.many_to_many or field.many_to_one):
     107            if not (field.many_to_many or field.many_to_one or field.one_to_one):
    108108                return must_be(
    109                     'a foreign key or a many-to-many field',
     109                    'a foreign key, a one-to-one field or a many-to-many field',
    110110                    option=label, obj=obj, id='admin.E038'
    111111                )
    112112            related_admin = obj.admin_site._registry.get(field.remote_field.model)
  • tests/admin_checks/models.py

    diff --git a/tests/admin_checks/models.py b/tests/admin_checks/models.py
    index 3336ce878e..e41def39e1 100644
    a b class Influence(models.Model):  
    6464    content_type = models.ForeignKey(ContentType, models.CASCADE)
    6565    object_id = models.PositiveIntegerField()
    6666    content_object = GenericForeignKey('content_type', 'object_id')
     67
     68
     69class User(models.Model):
     70    name = models.CharField(max_length=1024)
     71
     72
     73class ProfileUser(models.Model):
     74    user = models.OneToOneField(User, models.CASCADE)
     75    birthdate = models.DateField()
  • tests/admin_checks/tests.py

    diff --git a/tests/admin_checks/tests.py b/tests/admin_checks/tests.py
    index f4fabef301..454e36baf7 100644
    a b from django.core import checks  
    66from django.test import SimpleTestCase, override_settings
    77
    88from .models import (
    9     Album, Author, Book, City, Influence, Song, State, TwoAlbumFKAndAnE,
     9    Album, Author, Book, City, Influence, ProfileUser, Song, State,
     10    TwoAlbumFKAndAnE, User,
    1011)
    1112
    1213
    class SystemChecksTestCase(SimpleTestCase):  
    127128            admin.site.unregister(Book)
    128129            admin.site.unregister(Author)
    129130
     131    def test_autocomplete_onetoone_field(self):
     132
     133        class UserAdmin(admin.ModelAdmin):
     134            search_fields = ('name', )
     135
     136        class ProfileUserAdmin(admin.ModelAdmin):
     137            autocomplete_fields = ('user', )
     138
     139        admin.site.register(User, UserAdmin)
     140        admin.site.register(ProfileUser, ProfileUserAdmin)
     141        try:
     142            self.assertEqual(admin.site.check(None), [])
     143        finally:
     144            admin.site.unregister(User)
     145            admin.site.unregister(ProfileUser)
     146
    130147    def test_field_name_not_in_list_display(self):
    131148        class SongAdmin(admin.ModelAdmin):
    132149            list_editable = ["original_release"]
Back to Top