On Sun, Jun 29, 2008 at 11:27 AM, AdamC <[EMAIL PROTECTED]> wrote:

>
> I have a couple of models whereby the admin interface is throwing up
> some errors when I try add details to the user profile.
>
> Each user will have a points score and belong to a team, which will
> aggregate all the scores of those users belonging to that team.
>
> My models look thus:
>
>  class Team(models.Model):
>    team = models.TextField(unique=True)
>    def __str__(self):
>        return self.team
>    class Admin:
>        pass
>
> class UserProfile(models.Model):
>    score = models.IntegerField()
>    #team = models.ForeignKey(Team)
>    user = models.ForeignKey(User)
>    def __str__(self):
>        return self.user
>    class Admin:
>        pass
>
> When I go to a user's profile in the admin interface I get the error:
>
> TypeError at /admin/tables/userprofile/1/
> __str__ returned non-string (type User)
> Request Method:         GET
> Request URL:    http://localhost:8000/admin/tables/userprofile/1/
> Exception Type:         TypeError
> Exception Value:        __str__ returned non-string (type User)
> Exception Location:
>        /usr/lib/python2.5/site-packages/django/utils/encoding.py in
> force_unicode, line 53
>
> Template error
>
> In template
> /usr/lib/python2.5/site-packages/django/contrib/admin/templates/admin/change_form.html,
> error at line 14
> Caught an exception while rendering: __str__ returned non-string (type
> User)
>

Your UserProfile __str__ function is returning a User object, not a string.
It needs to return a string, since it is called to produce a string
representation of your Model.  If you want to return the string
representation of the associated user, return str(self.user).


> The score is an integer, but it seems that the template is expecting a
> string, when I definitely don't want it to be a string.
>

The error you have posted has nothing to do with score.

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