views:

309

answers:

2

Hi all,

I've posted this on django-users but haven't received a reply!

So I have my own profile objects for users (subclass of User). One of the fields is imagefield, which is (obviously) used for users to upload their logo/thumbnail.

The question is how I can include this on their comments?

Any ideas? Thanks in advance!

+8  A: 

Subclassing User is not recommended in Django. Instead, create a separate profile model.

Let's assume you have your app, foo.

In foo's models.py, add:

class FooUserProfile(models.Model):
   user = models.ForeignKey(User, unique=True)
   user_image = models.ImageField()

Then, in your settings.py, add:

AUTH_PROFILE_MODULE = 'foo.FooUserProfile'

Now, whenever you have a user object, you can get its profile object with the get_profile() function. In your case, in the template you could add:

<img src="{{ comment.user.get_profile.user_image }}"/>

A caveat: you will need to create a FooUserProfile and associate it with your User any time you create new User.

You can read more in the Django documentation, Storing additional information about users or in the article Django tips: extending the User model

Matthew Christensen
A: 

Hey, Matthew, that was exactly what I needed! You have no idea how much time you've saved me!

Best regards!

Markos Gogoulos
Glad I could help.
Matthew Christensen
This isn't an answer.
Ian P