python - Something's not quite right with my template tags -


is if statement? works, not correctly. no error comes , display number associated each word value won't display correct word , front end.

<p class="accent list-text">i'm a:</p> {% if request.user.userprofile.user_type == 1 %}     <p class="profile-info list-text">designer</p> {% elif request.user.userprofile.user_type == 2 %}     <p class="profile-info list-text">designer</p> {% else %}     <p class="profile-info list-text">both</p> {% endif %} 

models.py:

from django.db import models django.utils import timezone django.contrib.auth.models import user users.choices import * django.db.models.signals import post_save django.dispatch import receiver  # create models here. class userprofile(models.model):     user = models.onetoonefield(user, on_delete=models.cascade)      first_name = models.charfield(max_length=50,default='user')     join_date = models.datetimefield(default=timezone.now)     profile_pic = models.imagefield(upload_to='profile_pics',null=true,blank=true)     location = models.charfield(max_length=150)     title = models.charfield(max_length=250)     user_type = models.integerfield(choices=user_type_choices,default=1)     website = models.urlfield(max_length=100,blank=true)     = models.textfield(max_length=500,default='about')     twitter = models.charfield(max_length=50,blank=true)     dribbble = models.charfield(max_length=50,blank=true)     github = models.charfield(max_length=50,blank=true)      @receiver(post_save, sender=user)     def create_user_profile(sender, instance, created, **kwargs):         if created:             userprofile.objects.create(user=instance)      @receiver(post_save, sender=user)     def save_user_profile(sender, instance, **kwargs):         instance.userprofile.save()      def __str__(self):         return self.user.username 

choices.py:

user_type_choices = (     (1, ("designer")),     (2, ("developer")),     (3, ("both")), ) 

in userprofile model

just use charfield choices , work fine.

user_type_choices = (     ('1', 'designer'),     ('2', 'developer'),     ('3', 'both'), )  user_type = models.charfield(max_length=1,choices=user_type_choices,default='1') 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -