Thursday, October 18, 2012

loop user.get_profile displays none in a template

Hi,pal !  in a template,

{{ user.get_profile.user }}
{{ user.get_profile.birthday }}
{{ user.get_profile.name }}
{% for key,value in user.get_profile.items %}{{ value }}{% endfor %}

the last line doesnt work and displays none . Any guidance would be greatly appreciated.

models.py:

class UserProfile(models.Model):
    # This field is required.
    user = models.OneToOneField(User)

    # Other fields here
    birthday = models.DateField()
    name     = models.CharField(max_length=100)
    favorite_animal = models.CharField(max_length=20, default="Dragons.")
   
    def __unicode__(self):
                return self.name


def create_user_profile(sender, instance, created, **kwargs):
    if created:
        UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/4Oej4wsYap0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate