# O que aprendi?

* <mark style="background-color:yellow;">uma</mark> <mark style="background-color:yellow;"></mark><mark style="background-color:yellow;">`Disciplina`</mark> <mark style="background-color:yellow;"></mark><mark style="background-color:yellow;">tem muitos alunos e uma aluno tem muitas disciplinas</mark>
* <mark style="background-color:yellow;">É uma relação</mark> <mark style="background-color:yellow;"></mark><mark style="background-color:yellow;">`Aluno`</mark> <mark style="background-color:yellow;"></mark><mark style="background-color:yellow;">**N:N**</mark> <mark style="background-color:yellow;"></mark><mark style="background-color:yellow;">`Disciplina`</mark>
* <mark style="background-color:yellow;">em django modela-se com relação</mark> <mark style="background-color:yellow;">**`ManyToManyField`**</mark>

```python
# models.py

from django.db import models

class Aluno(models.Model):
    nome = models.CharField(max_length=100)
    disciplinas = models.ManyToManyField(Disciplina, related_name="alunos") # relacao Aluno M:N Disciplina
    
class Disciplina(models.Model):
    nome = models.CharField(max_length=100)
```

<mark style="background-color:yellow;">**Alternativamente, podemos pôr a relação N:N em disciplina, mas nunca nos dois!**</mark>

```python
# models.py

from django.db import models

class Aluno(models.Model):
    nome = models.CharField(max_length=100)
    
class Disciplina(models.Model):
    nome = models.CharField(max_length=100)
    alunos = models.ManyToManyField(Aluno, related_name="disciplinas") # relacao Aluno M:N Disciplina
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://programacao-web.gitbook.io/erros-comuns/erros-comuns-de-modelacao-django/1.-relacao-aluno-disciplina/o-que-aprendi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
