djangodjango-modelsdjango-templatesdjango-profiles

I can't display extended values of my user model


On this case my problem arise displaying extended values of my user model in my index.html

here my models.py

from django.db import models
from django.contrib.auth.models import User

def url(self,filename):
    ruta = "MultimediaData/Users/%s/%s"%(self.user.username,filename)
    return ruta

class userProfile(models.Model):    

    user = models.OneToOneField(User)
    photo = models.ImageField(upload_to=url)
    telefono = models.CharField(max_length=30)
    email = models.EmailField(max_length=75)

    def __unicode__(self):
        return self.user.username

my index.html:

{% extends 'base.html' %}
{% block title %} Inicio - Bienvenidos {% endblock %}
{% block content %} 
<p>Dracoin, el portal que facilitará tu vida</p>
{% if user.is_authenticated %}
    <p>Bienvenido {{ user.username }}</p>
    {% if user.get_profile.photo %}
        <img src="/media/{{user.get_profile.photo}}" width="100px" height="100px"/>
    {% endif %}
    {% if user.get_profile.telefono %}
        <p>Numero Tel: {{user.get_profile.telefono}}</p>
    {% endif %}
{% endif %}
{% endblock %}

I don't have problem managing that information in my admin panel but i cant view that information in my index. I believe the mistake is in {% if user.get_profile.xxxx %} calling but I cant solve it.

apologizeme in advance if I overlook something.

Thanks!!


Solution

  • get_profile() was deprecated in django 1.5, and removed in django 1.7.

    Try {{ user.userprofile.xxxx }} instead.