【发布时间】:2014-10-06 06:40:13
【问题描述】:
我想在子项目中显示为每个作者编写的 Authors 和 Books 的树,
比如show in the image 和...我有两个模型Author 和Book 处于OneToMany 关系中。
#models.py
from django.db import models
class Author(models.Model):
Name = models.CharField(max_length = 250)
def __unicode__(self):
return self.Name
class Book(models.Model):
Title = models.CharField(max_length = 250)
def __unicode__(self):
return self.Title
#views.py
from django.shortcuts import render, get_object_or_404
from django.views.generic import TemplateView, ListView
from .models import InstanciaJudicial, SedeJudicial
class Prueba(ListView):
model = SedeJudicial
template_name = 'instancias/pruebas.html'
我知道我定义了get_queryset 和get_context_data,但我不知道我是怎么做到的。
【问题讨论】:
-
模型之间的关系在哪里?
标签: python django django-models django-templates django-views