#8648: Admin ignores to_field on ForeignKey
--------------------------------------+-------------------------------------
          Reporter:  kmtracey         |         Owner:  nobody
            Status:  new              |     Milestone:  1.0   
         Component:  Admin interface  |       Version:  SVN   
        Resolution:                   |      Keywords:        
             Stage:  Accepted         |     Has_patch:  1     
        Needs_docs:  0                |   Needs_tests:  0     
Needs_better_patch:  0                |  
--------------------------------------+-------------------------------------
Comment (by kmtracey):

 Replying to [comment:9 SmileyChris]:
 > Taking a step back, it seems that the choices should be using the
 `to_field` as it's key rather than the primary key. I attached a patch
 (with tests) which does this.

 I verified that works for the default case, but there's still a problem
 (same exception as without the patch) if that field is included in
 `raw_id_fields`.  Attempting to bring up a change page for an Inventory
 with non-null parent, I get:

 {{{
 Environment:

 Request Method: GET
 Request URL: http://localhost:8000/admin/selfref/inventory/3/
 Django Version: 1.0-beta_2-SVN-8781
 Python Version: 2.5.2
 Installed Applications:
 ['django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.sites',
  'django.contrib.admin',
  'django.contrib.sitemaps',
  'django.contrib.flatpages',
  'playground.selfref']
 Installed Middleware:
 ('django.middleware.common.CommonMiddleware',
  'django.contrib.sessions.middleware.SessionMiddleware',
  'django.contrib.auth.middleware.AuthenticationMiddleware',
  'django.middleware.doc.XViewMiddleware',
  'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')


 Template error:
 In template
 
d:\u\kmt\django\trunk\django\contrib\admin\templates\admin\includes\fieldset.html,
 error at line 11
    Caught an exception while rendering: Inventory matching query does not
 exist.
    1 : <fieldset class="module aligned {{ fieldset.classes }}">
    2 :   {% if fieldset.name %}<h2>{{ fieldset.name }}</h2>{% endif %}
    3 :   {% if fieldset.description %}<div class="description">{{
 fieldset.description|safe }}</div>{% endif %}
    4 :   {% for line in fieldset %}
    5 :       <div class="form-row{% if line.errors %} errors{% endif %} {%
 for field in line %}{{ field.field.name }} {% endfor %} ">
    6 :       {{ line.errors }}
    7 :       {% for field in line %}
    8 :           {% if field.is_checkbox %}
    9 :               {{ field.field }}{{ field.label_tag }}
    10 :           {% else %}
    11 :               {{ field.label_tag }} {{ field.field }}
    12 :           {% endif %}
    13 :           {% if field.field.field.help_text %}<p class="help">{{
 field.field.field.help_text|safe }}</p>{% endif %}
    14 :       {% endfor %}
    15 :       </div>
    16 :   {% endfor %}
    17 : </fieldset>
    18 :

 Traceback:
 File "d:\u\kmt\django\trunk\django\core\handlers\base.py" in get_response
   86.                 response = callback(request, *callback_args,
 **callback_kwargs)
 File "d:\u\kmt\django\trunk\django\contrib\admin\sites.py" in root
   173.                 return self.model_page(request, *url.split('/', 2))
 File "d:\u\kmt\django\trunk\django\views\decorators\cache.py" in
 _wrapped_view_func
   44.         response = view_func(request, *args, **kwargs)
 File "d:\u\kmt\django\trunk\django\contrib\admin\sites.py" in model_page
   192.         return admin_obj(request, rest_of_url)
 File "d:\u\kmt\django\trunk\django\contrib\admin\options.py" in __call__
   196.             return self.change_view(request, unquote(url))
 File "d:\u\kmt\django\trunk\django\db\transaction.py" in
 _commit_on_success
   238.                 res = func(*args, **kw)
 File "d:\u\kmt\django\trunk\django\contrib\admin\options.py" in
 change_view
   620.         return self.render_change_form(request, context,
 change=True, obj=obj)
 File "d:\u\kmt\django\trunk\django\contrib\admin\options.py" in
 render_change_form
   402.         ], context,
 context_instance=template.RequestContext(request))
 File "d:\u\kmt\django\trunk\django\shortcuts\__init__.py" in
 render_to_response
   18.     return HttpResponse(loader.render_to_string(*args, **kwargs),
 **httpresponse_kwargs)
 File "d:\u\kmt\django\trunk\django\template\loader.py" in render_to_string
   107.     return t.render(context_instance)
 File "d:\u\kmt\django\trunk\django\template\__init__.py" in render
   176.         return self.nodelist.render(context)
 File "d:\u\kmt\django\trunk\django\template\__init__.py" in render
   768.                 bits.append(self.render_node(node, context))
 File "d:\u\kmt\django\trunk\django\template\debug.py" in render_node
   71.             result = node.render(context)
 File "d:\u\kmt\django\trunk\django\template\loader_tags.py" in render
   97.         return compiled_parent.render(context)
 File "d:\u\kmt\django\trunk\django\template\__init__.py" in render
   176.         return self.nodelist.render(context)
 File "d:\u\kmt\django\trunk\django\template\__init__.py" in render
   768.                 bits.append(self.render_node(node, context))
 File "d:\u\kmt\django\trunk\django\template\debug.py" in render_node
   71.             result = node.render(context)
 File "d:\u\kmt\django\trunk\django\template\loader_tags.py" in render
   97.         return compiled_parent.render(context)
 File "d:\u\kmt\django\trunk\django\template\__init__.py" in render
   176.         return self.nodelist.render(context)
 File "d:\u\kmt\django\trunk\django\template\__init__.py" in render
   768.                 bits.append(self.render_node(node, context))
 File "d:\u\kmt\django\trunk\django\template\debug.py" in render_node
   71.             result = node.render(context)
 File "d:\u\kmt\django\trunk\django\template\loader_tags.py" in render
   24.         result = self.nodelist.render(context)
 File "d:\u\kmt\django\trunk\django\template\__init__.py" in render
   768.                 bits.append(self.render_node(node, context))
 File "d:\u\kmt\django\trunk\django\template\debug.py" in render_node
   71.             result = node.render(context)
 File "d:\u\kmt\django\trunk\django\template\defaulttags.py" in render
   148.                 nodelist.append(node.render(context))
 File "d:\u\kmt\django\trunk\django\template\loader_tags.py" in render
   111.             return self.template.render(context)
 File "d:\u\kmt\django\trunk\django\template\__init__.py" in render
   176.         return self.nodelist.render(context)
 File "d:\u\kmt\django\trunk\django\template\__init__.py" in render
   768.                 bits.append(self.render_node(node, context))
 File "d:\u\kmt\django\trunk\django\template\debug.py" in render_node
   71.             result = node.render(context)
 File "d:\u\kmt\django\trunk\django\template\defaulttags.py" in render
   148.                 nodelist.append(node.render(context))
 File "d:\u\kmt\django\trunk\django\template\defaulttags.py" in render
   148.                 nodelist.append(node.render(context))
 File "d:\u\kmt\django\trunk\django\template\defaulttags.py" in render
   246.             return self.nodelist_false.render(context)
 File "d:\u\kmt\django\trunk\django\template\__init__.py" in render
   768.                 bits.append(self.render_node(node, context))
 File "d:\u\kmt\django\trunk\django\template\debug.py" in render_node
   81.             raise wrapped

 Exception Type: TemplateSyntaxError at /admin/selfref/inventory/3/
 Exception Value: Caught an exception while rendering: Inventory matching
 query does not exist.

 Original Traceback (most recent call last):
   File "d:\u\kmt\django\trunk\django\template\debug.py", line 71, in
 render_node
     result = node.render(context)
   File "d:\u\kmt\django\trunk\django\template\debug.py", line 87, in
 render
     output = force_unicode(self.filter_expression.resolve(context))
   File "d:\u\kmt\django\trunk\django\utils\encoding.py", line 49, in
 force_unicode
     s = unicode(s)
   File "d:\u\kmt\django\trunk\django\forms\forms.py", line 311, in
 __unicode__
     return self.as_widget()
   File "d:\u\kmt\django\trunk\django\forms\forms.py", line 339, in
 as_widget
     return widget.render(self.html_name, data, attrs=attrs)
   File "d:\u\kmt\django\trunk\django\contrib\admin\widgets.py", line 122,
 in render
     output.append(self.label_for_value(value))
   File "d:\u\kmt\django\trunk\django\contrib\admin\widgets.py", line 127,
 in label_for_value
     truncate_words(self.rel.to.objects.get(pk=value), 14)
   File "d:\u\kmt\django\trunk\django\db\models\manager.py", line 81, in
 get
     return self.get_query_set().get(*args, **kwargs)
   File "d:\u\kmt\django\trunk\django\db\models\query.py", line 301, in get
     % self.model._meta.object_name)
 DoesNotExist: Inventory matching query does not exist.

 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8648#comment:10>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to