[pyar] FieldDoesNotExist('%s has no field named %r' % (self.object_name, name))

Jonathan G Linenberg jlinenberg en gmail.com
Sab Abr 7 14:57:28 ART 2012


El 7 de abril de 2012 14:26, Felipe Lerena <felipelerena en gmail.com>escribió:

> El problema es que estas traduciendo el nombre del campo.  Lo que tendrías
> que traducir es el label del charfield
>
> Lipe
> On Apr 7, 2012 2:02 PM, "Jonathan G Linenberg" <jlinenberg en gmail.com>
> wrote:
>
>> Gente como va?
>>
>> Hace 2 días vengo googleando este problema y no encuentro solución. En
>> los modelos de django tengo esto:
>>
>> *models.py*
>>
>> from django.db import models
>> from django.utils.translation import ugettext_lazy as _
>>
>>
>> #===============================================================================
>> # Province model
>>
>> #===============================================================================
>> class Province(models.Model):
>>     name = models.CharField(_('name'), max_length=30)
>>
>>     class Meta:
>>         verbose_name = _('province')
>>         verbose_name_plural = _('provinces')
>>
>>     def __unicode__(self):
>>         return u'%s' % (self.name)
>>
>> #------------------------------------------------------------------------------
>>
>> Y cuando hago un *python manage.py syncdb* obtengo:
>>
>> Traceback (most recent call last):
>>   File
>> "C:\Users\Linenberg\Dropbox\WorkSpace\RescueCommittee\RescueCommittee\manage.py",
>> line 14, in <module>
>>     execute_manager(settings)
>>   File
>> "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
>> 438, in execute_manager
>>     utility.execute()
>>   File
>> "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
>> 379, in execute
>>     self.fetch_command(subcommand).run_from_argv(self.argv)
>>   File "C:\Python27\lib\site-packages\django\core\management\base.py",
>> line 191, in run_from_argv
>>     self.execute(*args, **options.__dict__)
>>   File "C:\Python27\lib\site-packages\django\core\management\base.py",
>> line 219, in execute
>>     self.validate()
>>   File "C:\Python27\lib\site-packages\django\core\management\base.py",
>> line 249, in validate
>>     num_errors = get_validation_errors(s, app)
>>   File
>> "C:\Python27\lib\site-packages\django\core\management\validation.py", line
>> 122, in get_validation_errors
>>     if not f.rel.to._meta.get_field(f.rel.field_name).unique:
>>   File "C:\Python27\lib\site-packages\django\db\models\options.py", line
>> 289, in get_field
>>     raise FieldDoesNotExist('%s has no field named %r' %
>> (self.object_name, name))
>> django.db.models.fields.FieldDoesNotExist: Province has no field named
>> <django.utils.functional.__proxy__ object at 0x00000000039A6780>
>>
>> Si alguno le paso y puede arrojarme algo de luz en este problema se lo
>> voy a agradecer!
>>
>> Saludos!
>> --
>> *Jonathan G. Linenberg*
>> Linux User # 521828
>>
>> _______________________________________________
>> pyar mailing list pyar en python.org.ar
>> http://listas.python.org.ar/listinfo/pyar
>>
>> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>>
>> La lista de PyAr esta Hosteada en USLA - Usuarios de Software Libre de
>> Argentina - http://www.usla.org.ar
>>
>
> _______________________________________________
> pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/listinfo/pyar
>
> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>
> La lista de PyAr esta Hosteada en USLA - Usuarios de Software Libre de
> Argentina - http://www.usla.org.ar
>

Gracias Felipe por tu respuesta!

Estuve googleando un poco y encontre esto:

" The form field's label is set to the verbose_name of the model field,
with the first character capitalized. "

Así que modifique mis modelos:

from django.db import models
from django.utils.translation import ugettext_lazy as _

#===============================================================================
# Province model
#===============================================================================
class Province(models.Model):
    name = models.CharField(verbose_name=_('name'), max_length=30)

    class Meta:
        verbose_name = _('province')
        verbose_name_plural = _('provinces')

    def __unicode__(self):
        return u'%s' % (self.name)
#------------------------------------------------------------------------------

El tema es que por mas ponga _('name') o _('province') el resultado sigue
siendo el mismo. Vos a que te referis con cambiar o referenciar al label
del campo?

Saludos!
--
*Jonathan G. Linenberg*
Linux User # 521828
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20120407/2740aa5c/attachment.html>


More information about the pyar mailing list