我的模型:
class Aula(models.Model):
nome_aula = models.CharField(max_length=255)
descricao_aula = models.TextField()
...
def __str__(self):
return self.nome_aula
class Modulos(models.Model):
numero_modulo = models.CharField(default="Módulo 1",max_length=400)
aulas = models.ManyToManyField(Aula)
def __str__(self):
return self.numero_modulo
我的观点:
def aulasdomodulo(request, id):
mod = get_object_or_404(Modulos, pk=id)
aulas = mod.aulas.all()
return render(request, 'wtic/aulasdomodulo.html', {'aulas':aulas, 'mod':mod})
def conteudodaaula(request, id):
mod2 = get_object_or_404(Modulos, pk=id)
aula = mod2.aulas.all()
...
return render(request,'wtic/conteudo_aula.html', {'aula':aula})
我的 html 显示分配给该模块访问它们的对象
{% for aula in aulas %}
{{aula.nome_aula}}
<a href="/aula/{{aula.id}}">Acessar</a>
{% endfor %}
但是当我尝试访问课程时,我明白了
如何每页访问一个这些对象?