Created
August 21, 2014 01:13
-
-
Save xiaotangyuan/0e61f695e139faa52d6c to your computer and use it in GitHub Desktop.
ForeignKey的related_name用法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProjectStyle(models.Model): | |
name=models.CharField(max_length=50) | |
def __unicode__(self): | |
return self.name | |
class GuanZhu(models.Model): | |
guanzhu=models.ForeignKey(ProjectStyle) | |
user=models.ForeignKey(BaseInfo,related_name='guanzhus') | |
# 可以通过在模板中如下使用 | |
{% for gz in u.guanzhus.all %} | |
<span>{{gz.guanzhu.name}}</span> | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment