get user profile info in templates

50 views
Skip to first unread message

sourav

unread,
Apr 24, 2014, 4:41:05 AM4/24/14
to django...@googlegroups.com
hi i am a newbie in django i am creating an app with customuser and profile

i want get user profile information  in templates who is logged in.
try everypossible solution but didn't achieve anything

this is my profile models code below:

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

from CustomUserAuth.models import CustomUser


class ProfileModel(models.Model):
        user = models.OneToOneField(CustomUser)
        avatar = models.ImageField(_('Profile Pic'),upload_to='images/')
        first_name = models.CharField(_('First Name'),max_length=100)
        last_name = models.CharField(_('Last Name'),max_length=100)
        company = models.CharField(_('Company'),max_length=100)
        title = models.CharField(_('Title'),max_length=100)

        def __str__(self):
                return '%s %s' % (self.first_name,self.last_name)

        def image_tag(self):
                return u'<img src="%s"/>' % (self.avatar.url)
        image_tag.short_description = 'Image'
        image_tag.allow_tags = True

CustomUser.profile = property(lambda u: ProfileModel.objects.get_or_create(user=u)[0])

Ramón Carrillo

unread,
Apr 24, 2014, 11:58:23 AM4/24/14
to django...@googlegroups.com
Hi,

Did you set CustomUserAuth as your auth model in settings.py? [1]

[0] https://docs.djangoproject.com/en/1.6/ref/settings/#std:setting-AUTH_USER_MODEL
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c4673b6c-f888-4fdb-8016-a6f2ece77568%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages