Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14424 -- corrected a NameError when instantiating a RelatedFie…

…ldWidgetWrapper.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14683 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3498849532151f618ff36eea4bd315de6f500687 1 parent 07ba322
Alex Gaynor authored
2  django/contrib/admin/widgets.py
@@ -203,7 +203,7 @@ def __init__(self, widget, rel, admin_site, can_add_related=None):
203 203
         # Backwards compatible check for whether a user can add related
204 204
         # objects.
205 205
         if can_add_related is None:
206  
-            can_add_related = rel_to in self.admin_site._registry
  206
+            can_add_related = rel.to in admin_site._registry
207 207
         self.can_add_related = can_add_related
208 208
         # so we can check if the related object is registered with this AdminSite
209 209
         self.admin_site = admin_site
5  tests/regressiontests/admin_widgets/models.py
... ...
@@ -1,8 +1,9 @@
1 1
 from django.db import models
2 2
 from django.contrib.auth.models import User
3 3
 
4  
-class MyFileField(models.FileField): 
5  
-    pass 
  4
+
  5
+class MyFileField(models.FileField):
  6
+    pass
6 7
 
7 8
 class Member(models.Model):
8 9
     name = models.CharField(max_length=100)
17  tests/regressiontests/admin_widgets/tests.py
@@ -6,9 +6,9 @@
6 6
 from django.conf import settings
7 7
 from django.contrib import admin
8 8
 from django.contrib.admin import widgets
9  
-from django.contrib.admin.widgets import FilteredSelectMultiple, AdminSplitDateTime
10  
-from django.contrib.admin.widgets import (AdminFileWidget, ForeignKeyRawIdWidget,
11  
-    ManyToManyRawIdWidget)
  9
+from django.contrib.admin.widgets import (FilteredSelectMultiple,
  10
+    AdminSplitDateTime, AdminFileWidget, ForeignKeyRawIdWidget, AdminRadioSelect,
  11
+    RelatedFieldWidgetWrapper, ManyToManyRawIdWidget)
12 12
 from django.core.files.storage import default_storage
13 13
 from django.core.files.uploadedfile import SimpleUploadedFile
14 14
 from django.db.models import DateField
@@ -31,7 +31,8 @@ def assertFormfield(self, model, fieldname, widgetclass, **admin_overrides):
31 31
         and verify that the returned formfield is appropriate.
32 32
         """
33 33
         # Override any settings on the model admin
34  
-        class MyModelAdmin(admin.ModelAdmin): pass
  34
+        class MyModelAdmin(admin.ModelAdmin):
  35
+            pass
35 36
         for k in admin_overrides:
36 37
             setattr(MyModelAdmin, k, admin_overrides[k])
37 38
 
@@ -314,3 +315,11 @@ def test_render(self):
314 315
         self.assertEqual(w._has_changed([1, 2], [u'1', u'2']), False)
315 316
         self.assertEqual(w._has_changed([1, 2], [u'1']), True)
316 317
         self.assertEqual(w._has_changed([1, 2], [u'1', u'3']), True)
  318
+
  319
+class RelatedFieldWidgetWrapperTests(DjangoTestCase):
  320
+    def test_no_can_add_related(self):
  321
+        rel = models.Inventory._meta.get_field('parent').rel
  322
+        w = AdminRadioSelect()
  323
+        # Used to fail with a name error.
  324
+        w = RelatedFieldWidgetWrapper(w, rel, admin.site)
  325
+        self.assertFalse(w.can_add_related)

0 notes on commit 3498849

Please sign in to comment.
Something went wrong with that request. Please try again.