models.py
from django.db import models
class Aluno(models.Model):
nome = models.CharField(max_length=30)
rg = models.CharField(max_length=9)
cpf = models.CharField(max_length=11)
data_nascimento = models.DateField()
def __str__(self):
return self.nome
class Curso(models.Model):
NIVEL = (
('B', 'Básico'),
('I', 'Intermediário'),
('A', 'Avançado')
)
codigo_curso = models.CharField(max_length=10)
descricao = models.CharField(max_length=100)
nivel = models.CharField(max_length=1, choices=NIVEL, blank=False, null=False,default='B')
def __str__(self):
return self.descricao
class Matricula(models.Model):
PERIODO = (
('M', 'Matutino'),
('V', 'Vespertino'),
('N', 'Noturno')
)
aluno = models.ForeignKey(Aluno, on_delete=models.CASCADE)
curso = models.ForeignKey(Curso, on_delete=models.CASCADE)
periodo = models.CharField(max_length=1, choices=PERIODO, blank=False, null=False, default='M')
admin.py
from django.contrib import admin
from escola.models import Aluno, Curso, Matricula
class Alunos(admin.ModelAdmin):
list_display = ('id', 'nome', 'rg', 'cpf', 'data_nascimento')
list_display_links = ('id', 'nome')
search_fields = ('nome',)
list_per_page = 20
admin.site.register(Aluno, Alunos)
class Cursos(admin.ModelAdmin):
list_display = ('id', 'codigo_curso', 'descricao')
list_display_links = ('id', 'codigo_curso')
search_fields = ('codigo_curso',)
admin.site.register(Curso, Cursos)
class Matriculas(admin.ModelAdmin):
list_display = ('id', 'aluno', 'curso', 'periodo')
list_display_links = ('id')
admin.site.register(Matricula, Matriculas)
> python manage.py makemigrations
ERRORS:
<class 'escola.admin.Matriculas'>: (admin.E110) The value of 'list_display_links' must be a list, a tuple, or None.
Traceback (most recent call last):
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 366, in execute
self.check()
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 441, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
<class 'escola.admin.Matriculas'>: (admin.E110) The value of 'list_display_links' must be a list, a tuple, or None.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 338, in run_from_argv
sys.exit(1)
SystemExit: 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\angelo\Documents\curso_django\manage.py", line 22, in <module> main()
File "C:\Users\angelo\Documents\curso_django\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 341, in run_from_argv
connections.close_all()
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\utils.py", line 230, in close_all
connection.close()
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\sqlite3\base.py", line 261, in close
if not self.is_in_memory_db():
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\sqlite3\base.py", line 380, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict['NAME'])
File "C:\Users\angelo\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\sqlite3\creation.py", line 12, in is_in_memory_db
return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'WindowsPath' is not iterable