我有这样的 User、UserClient 和 Client 模型:
一个客户端可以有多个用户:
class Client(models.Model):
user = models.OneToOneField(User)
# Which company the client represents
company = models.CharField(max_length=200, null=True)
# Address of the company
address = models.CharField(max_length=200, null=True)
company_size = models.ForeignKey(CompanySize, null=True)
account_type = models.ForeignKey(AccountType)
billing_address = models.CharField(max_length=254, null=True)
# Billing Information of the client
def __unicode__(self):
return self.user.username
class ClientUser(models.Model):
user = models.OneToOneField(User)
client = models.ForeignKey(Client)
def __unicode__(self):
return self.user.email
现在在模板中,我想这样做:
{% if user.is_client %}
{{ do_this }}
这该怎么做?