标签:href choice country create name .com class intro cts
class Country(models.Model):
name = models.CharField(max_length=30)
def __str__(self):
return self.name
class City(models.Model):
country = models.ForeignKey(Country, on_delete=models.CASCADE)
name = models.CharField(max_length=30)
def __str__(self):
return self.name
City.objects.create(name='xian', country_id=1)
City.objects.create(name='xian', country_instance)
c = Country.objects.get(id=1)
print(c.city_set.all())
跟related_name有关系: https://www.cnblogs.com/iiiiiher/p/9542094.html
https://docs.djangoproject.com/zh-hans/2.1/intro/tutorial03/
<h1>{{ question.question_text }}</h1>
<ul>
{% for choice in question.choice_set.all %}
<li>{{ choice.choice_text }}</li>
{% endfor %}
</ul>
City.objects.values('name','country__name')
标签:href choice country create name .com class intro cts
原文地址:https://www.cnblogs.com/iiiiiher/p/9560240.html