Sorry, here's the full traceback:

Environment:

Request Method: GET
Request URL: http://myproject.webfactional.com/admin/words/word/278/delete/
Django Version: 0.97-pre-SVN-7388
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.databrowse',
 'myproject.portfolio',
 'myproject.words',
 'myproject.news',
 'myproject.industryinsider',
 'sorl.thumbnail',
 'tagging']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Traceback:
File "/home/myproject/lib/python2.5/django/core/handlers/base.py" in
get_response
  82.                 response = callback(request, *callback_args,
**callback_kwargs)
File "/home/myproject/webapps/django/myproject/portfolio/
admin_views.py" in delete_stage_with_post_url
  43.   return django.contrib.admin.views.main.delete_stage(request,
app_label, model_name, object_id)
File "/home/myproject/lib/python2.5/django/contrib/admin/views/
decorators.py" in _checklogin
  62.             return view_func(request, *args, **kwargs)
File "/home/myproject/lib/python2.5/django/views/decorators/cache.py"
in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/home/myproject/lib/python2.5/django/contrib/admin/views/
main.py" in delete_stage
  516.     _get_deleted_objects(deleted_objects, perms_needed,
request.user, obj, opts, 1)
File "/home/myproject/lib/python2.5/django/contrib/admin/views/
main.py" in _get_deleted_objects
  457.                     nh(deleted_objects, current_depth, [u'%s:
%s' % (force_unicode(capfirst(related.opts.verbose_name)),
escape(sub_obj)), []])
File "/home/myproject/lib/python2.5/django/utils/functional.py" in
wrapper
  239.             return func(*args, **kwargs)
File "/home/myproject/lib/python2.5/django/utils/html.py" in escape
  32.     return mark_safe(force_unicode(html).replace('&',
'&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"',
'&quot;').replace("'", '&#39;'))
File "/home/myproject/lib/python2.5/django/utils/encoding.py" in
force_unicode
  51.                 s = unicode(s)

Exception Type: TypeError at /admin/words/word/278/delete/
Exception Value: coercing to Unicode: need string or buffer, Word
found


On Apr 2, 2:21 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Wed, Apr 2, 2008 at 11:41 AM, Josh <[EMAIL PROTECTED]> wrote:
>
> > I've created a sort of modified tagging system for the site I'm
> > working on. Because of the nature of the 'tags' I had to diverge a
> > little form the standard and my models look like this:
>
> > class Word(models.Model):
> >        word = models.CharField(max_length=30)
> >        slug = models.SlugField(prepopulate_from=("word",))
> >        alternate_spelling = models.CharField(max_length=30, blank=True)
> >        pronunciation = models.CharField(max_length=30, blank=True)
> >        pronunciation_example =
> > models.FileField(upload_to="pronunciations",
> > blank=True)
> >        notes = models.TextField(blank=True)
> >        categories = models.ManyToManyField("FoodWordsCategory",
> > blank=True)
>
> >        def __unicode__(self):
> >                return self.word
>
> >        def save(self):
> >                super(Word, self).save()
> >                foodwords.scan_for_word(self)
>
> >        class Admin:
> >                ordering = ('word',)
> >                search_fields = ['word', 'alternate_spelling',]
>
> > class WordedItem(models.Model):
> >        word = models.ForeignKey(Word)
> >        content_type = models.ForeignKey(ContentType)
> >        object_id = models.PositiveIntegerField()
> >        content_object = generic.GenericForeignKey('content_type',
> > 'object_id')
>
> >        def __unicode__(self):
> >                return self.word
>
> This should be return __unicode__(self.word)
>
>
>
>
>
>
>
>
>
> > This seems like it should be all well and good, and for the most part
> > it is. But I'm running into some strange issues that appear to be
> > related to the fact that WordedItem.word is a ForeignKey. For example:
>
> > >>> relations = word.wordeditem_set.all()
> > >>> relations
> > Traceback (most recent call last):
> >  File "<stdin>", line 1, in <module>
> >  File "/home/bostonchefs/lib/python2.5/django/db/models/query.py",
> > line 108, in __repr__
> >    return repr(self._get_data())
> >  File "/home/bostonchefs/lib/python2.5/django/db/models/base.py",
> > line 125, in __repr__
> >    return smart_str(u'<%s: %s>' % (self.__class__.__name__,
> > unicode(self)))
> > TypeError: coercing to Unicode: need string or buffer, Word found
>
> > Obviously the problem here is that a Word object is being returned
> > instead of a unicode string, and I can fix that by simple chaging the
> > def __unicode__(self) to return a simple string (return "string" is
> > fine for now). However even when I do that I'm still encountering what
> > appears to be the same problem elsewhere. If I create a Word object,
> > thanks to the custom save() method I wrote it automatically associates
> > itself with the appropriate objects (it does a search on the
> > appropriate database fields, &c). So essentially any time you create a
> > Word object you can be sure it's going to be associated with some
> > WordedItem objects. The problem comes in if you then try and delete
> > that Word object from the admin interface. When I do so, I get
> > basically the same error as above:
>
> > TypeError at /admin/words/word/278/delete/
> > coercing to Unicode: need string or buffer, Word found
>
> Since this is the error you haven't figured out yet, this is the one that
> really needs a full traceback in order for people to help figure out what is
> going on.
>
> > This happens even after I change __unicode__(self) to return "string".
> > But, if I try and delete the Word object from the command line it
> > successfully deletes both the Word and the related WordedItems. Does
> > anyone have any idea what might be going on here?
>
> Not yet.
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to