Hi all,
I got the same error again in my own code and the error was exposed. I
guess what got me before was that the admin interface code was not my
own and that the cause of the error was outside of the traceback. In
my own code it became clear immediately.
So, in case anyone is wondering, heres what caused the problem:
The model which contained a ForeignKey to the CategoryOfVacancyLUT
model had a __unicode__ method like this:
def __unicode__(self):
return self.category_of_vacancy
but since self.category_of_vacancy was of type CategoryOfVacancyLUT,
this obviously wasn't a unicode string as was expected to be returned
expected. A quick fix was to convert it to return
unicode(self.category_of_vacancy) (though obviously that wouldn't be a
particularly interesting string).
I hope this solves all my admin interface problems now...
2008/6/27 Daniel Kersten <[EMAIL PROTECTED]>:
> err, I made a minor typo. In my third block of text I referred to
> PrimaryLevelCategoryOfVacancyLUT, this is the same as
> CategoryOfVacancyLUT - I just shortened the other occurances because
> its such a long name. Just in case this is confusing ;-)
>
> 2008/6/27 Daniel Kersten <[EMAIL PROTECTED]>:
>> Hi John,
>>
>> I am using version 0.97-pre-SVN-7728. I've been getting similar errors
>> for the past two weeks or so. Don't know if I was getting them on an
>> earlier version of django too.
>>
>> Regarding 's', here are the local variables in force_unicode:
>> encoding: 'utf-8'
>> errors: 'strict'
>> s: Error in formatting: coercing to Unicode: need string or buffer,
>> CategoryOfVacancyLUT found
>> strings_only: False
>>
>> This value seems to have been passed down from some other function.
>> The previous entry in the traceback contains this "Error in
>> formatting: coercing to Unicode: need string or buffer,
>> PrimaryLevelCategoryOfVacancyLUT found" as the value of a variable
>> called "new_object", which is the variable on which force_unicode is
>> called.
>>
>> The value of new object is received on line 262 of
>> django/contrib/admin/views/main.py:
>> new_object = manipulator.save(new_data)
>>
>> and "new_data" is a QueryDict containing the data I typed into the
>> admin interface before hitting save.
>>
>> Thanks for the help,
>> Dan.
>>
>> 2008/6/27 [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>>>
>>> Hi Daniel,
>>>
>>> What version or Django are you using? It looks like you are using
>>> max_lenght in your models so I'm guessing you are using trunk (.97)?
>>>
>>> The errors seem to be unicode related. What is the value of "s" in s
>>> = unicode(s)
>>>
>>> J
>>>
>>> On Jun 27, 9:23 am, "Daniel Kersten" <[EMAIL PROTECTED]> wrote:
>>>> Hi,
>>>>
>>>> I'm (still) having some problems with django's admin interface. When I
>>>> try to save changes (or, occasionally, try to view entries, but I
>>>> suspect it's the same cause) to some of my models (not all, some of
>>>> them work) I get errors. Any help with deciphering the errors is
>>>> appreciated!
>>>>
>>>> Here is the traceback which django displays and, below that, I have
>>>> pasted the model which it is referring to.
>>>>
>>>> Environment:
>>>>
>>>> Request Method: POST
>>>> Request
>>>> URL:http://192.168.178.22:8000/admin/primary_level/advertvacancyprimary/add/
>>>> Django Version: 0.97-pre-SVN-7728
>>>> Python Version: 2.5.2
>>>> Installed Applications:
>>>> ['django.contrib.auth',
>>>> 'django.contrib.contenttypes',
>>>> 'django.contrib.sessions',
>>>> 'django.contrib.admin',
>>>> 'educationposts.apps.main',
>>>> 'educationposts.apps.disclaimers',
>>>> 'educationposts.apps.levels',
>>>> 'educationposts.apps.accounts',
>>>> 'educationposts.apps.levels.primary_level',
>>>> 'educationposts.apps.levels.pre_school',
>>>> 'educationposts.apps.levels.second_level',
>>>> 'educationposts.apps.levels.third_level',
>>>> 'educationposts.apps.levels.other_posts']
>>>> Installed Middleware:
>>>> ('django.middleware.locale.LocaleMiddleware',
>>>> 'django.middleware.common.CommonMiddleware',
>>>> 'django.contrib.sessions.middleware.SessionMiddleware',
>>>> 'django.contrib.auth.middleware.AuthenticationMiddleware',
>>>> 'django.middleware.doc.XViewMiddleware',
>>>> 'educationposts.apps.accounts.middleware.LoginMiddleware')
>>>>
>>>> Traceback:
>>>> File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
>>>> in get_response
>>>> 82. response = callback(request, *callback_args,
>>>> **callback_kwargs)
>>>> File
>>>> "/usr/lib/python2.5/site-packages/django/contrib/admin/views/decorators.py"
>>>> in _checklogin
>>>> 62. return view_func(request, *args, **kwargs)
>>>> File "/usr/lib/python2.5/site-packages/django/views/decorators/cache.py"
>>>> in _wrapped_view_func
>>>> 44. response = view_func(request, *args, **kwargs)
>>>> File "/usr/lib/python2.5/site-packages/django/contrib/admin/views/main.py"
>>>> in add_stage
>>>> 266. LogEntry.objects.log_action(request.user.id,
>>>> ContentType.objects.get_for_model(model).id, pk_value,
>>>> force_unicode(new_object), ADDITION)
>>>> File "/usr/lib/python2.5/site-packages/django/utils/encoding.py" in
>>>> force_unicode
>>>> 51. s = unicode(s)
>>>>
>>>> Exception Type: TypeError at /admin/primary_level/advertvacancyprimary/add/
>>>> Exception Value: coercing to Unicode: need string or buffer,
>>>> lCategoryOfVacancyLUT found
>>>>
>>>> The definition of CategoryOfVacancyLUT is:
>>>>
>>>> class lCategoryOfVacancyLUT(models.Model):
>>>> english = models.CharField(max_length=256)
>>>> gaeilge = models.CharField(max_length=256)
>>>> marked_as_deleted = models.BooleanField()
>>>>
>>>> def __unicode__(self):
>>>> return unicode(self.english)
>>>>
>>>> Note that I am only having problems with this in the admin interface.
>>>> All of my own code which reads or writes to these models works
>>>> perfectly. Is the current version of the admin interface broken? If
>>>> so, is it safe for me to ignore this (ie, will it magically work in a
>>>> future version)?
>>>> I also get other similar errors when modifying some of the other
>>>> models. If it is useful, I can paste details of those too.
>>>>
>>>> Thanks very much!
>>>> Dan.
>>>>
>>>> --
>>>> Daniel Kersten.
>>>> Leveraging dynamic paradigms since the synergies of 1985.
>>> >>>
>>>
>>
>>
>>
>> --
>> Daniel Kersten.
>> Leveraging dynamic paradigms since the synergies of 1985.
>>
>
>
>
> --
> Daniel Kersten.
> Leveraging dynamic paradigms since the synergies of 1985.
>
--
Daniel Kersten.
Leveraging dynamic paradigms since the synergies of 1985.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Python Ireland" 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.ie/group/pythonireland?hl=en
-~----------~----~----~----~------~----~------~--~---