Code

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#12187 closed (duplicate)

when a put a value in raw_id_fields it breaks

Reported by: jorge.w.machado@… Owned by: nobody
Component: Template system Version: 1.1
Severity: Keywords: TemplateSyntaxErro
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by Alex)

admin.py :

class Material_Admin(admin.ModelAdmin):
	list_display=('cod_mat','nome','tipo_de_material','unidade_material')
	list_filter = ('data_de_entrada','unidade_material')
	inlines= (Material_inter_Forne_Inline,)
	search_fields =('nome',)
	raw_id_fields =('unidade_material','tipo_de_material')

models.py

class Material(models.Model):
	cod_mat= models.CharField("código do material",max_length=6,primary_key=True)
	nome= models.CharField(max_length=20)
	tipo_de_material = models.ForeignKey(Tipo_material)
	unidade_material = models.ForeignKey(Unidade_material)
	data_de_entrada=models.DateField("data de inserção",default=date.today())
	#ForeignKey
	fornecedore= models.ManyToManyField(Fornecedor,through='Material_inter_Forne')
	def __unicode__(self):
				return '%s %s'%(self.cod_mat,self.nome)
	class Meta:
		verbose_name= u'Material'

when i put a value in the box left by raw_id_fields i have this traceback :

Environment:

Request Method: POST
Request URL: http://localhost:8000/admin/andrade_e_almeida/material/ma01/
Django Version: 1.1.1
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'si_andrade.andrade_e_almeida']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Template error:
In template /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/templates/admin/includes/fieldset.html, error at line 12
   Caught an exception while rendering: Unidade_material matching query does not exist.
   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 :       <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>


   9 :           {% if field.is_checkbox %}


   10 :               {{ field.field }}{{ field.label_tag }}


   11 :           {% else %}


   12 :               {{ field.label_tag }} {{ field.field }} 


   13 :           {% endif %}


   14 :           {% if field.field.field.help_text %}<p class="help">{{ field.field.field.help_text|safe }}</p>{% endif %}


   15 :       </div>


   16 :       {% endfor %}


   17 :       </div>


   18 :   {% endfor %}


   19 : </fieldset>


   20 : 

Traceback:
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/options.py" in wrapper
  226.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/sites.py" in inner
  186.             return view(request, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/transaction.py" in _commit_on_success
  240.                 res = func(*args, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/options.py" in change_view
  873.         return self.render_change_form(request, context, change=True, obj=obj)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/options.py" in render_change_form
  590.         ], context, context_instance=context_instance)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/loader.py" in render_to_string
  108.     return t.render(context_instance)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  24.         result = self.nodelist.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  155.                 nodelist.append(node.render(context))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  111.             return self.template.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  155.                 nodelist.append(node.render(context))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  155.                 nodelist.append(node.render(context))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  244.             return self.nodelist_false.render(context)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py" in render
  779.                 bits.append(self.render_node(node, context))
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py" in render_node
  81.             raise wrapped

Exception Type: TemplateSyntaxError at /admin/andrade_e_almeida/material/ma01/
Exception Value: Caught an exception while rendering: Unidade_material matching query does not exist.

Original Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py", line 87, in render
    output = force_unicode(self.filter_expression.resolve(context))
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/utils/encoding.py", line 71, in force_unicode
    s = unicode(s)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/forms/forms.py", line 356, in __unicode__
    return self.as_widget()
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/forms/forms.py", line 391, in as_widget
    return widget.render(name, data, attrs=attrs)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/widgets.py", line 127, in render
    output.append(self.label_for_value(value))
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/widgets.py", line 151, in label_for_value
    obj = self.rel.to._default_manager.get(**{key: value})
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/manager.py", line 120, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/models/query.py", line 305, in get
    % self.model._meta.object_name)
DoesNotExist: Unidade_material matching query does not exist.

can some help please ?

Attachments (0)

Change History (4)

comment:1 Changed 4 years ago by jorge.w.machado@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

i put it on dpaste to : http://dpaste.com/117619/

comment:2 Changed 4 years ago by Alex

  • Description modified (diff)

Please use the preview button.

comment:3 Changed 4 years ago by kmtracey

  • Resolution set to duplicate
  • Status changed from new to closed

You've apparently entered a value for the related field that does not exist. The fact that this triggers an exception instead of an error message is covered by #11465.

comment:4 Changed 4 years ago by anonymous

yes , but it should raise an validation error in the form rigth ?.. I'm new in django... the other tiket don't explain how to solve the problem

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.