I did a test with your code and it works perfectly, the only error I see in the code you posted here is in the fragment (admin.py):
class PacienteAdmin(ModelAdmin):
list_display = ('nome','data_nascimento')
Change the line:
class PacienteAdmin(ModelAdmin):
To:
class Paciente(models.Model):
If it doesn’t work, try to follow the steps:
1) (command line)
$ django-admin startproject myproject .
2) (command line)
$ ./manage.py migrate
3) (command line)
$ ./manage.py createsuperuser
4) (command line)
$ ./manage.py startapp myapp
After these steps, the tree of your project should look like the figure below:
5) Edit the models.py file in the myapp directory to look like this:
from django.db import models
class Paciente(models.Model):
nome = models.CharField(max_length=60)
data_nascimento = models.DateField()
def __str__(self):
return self.nome
class Meta:
verbose_name = "Paciente"
verbose_name_plural = "Pacientes"
6) Edit the admin file in myapp, so it looks like this:
from django.contrib import admin
from .models import Paciente
class PacienteAdmin(admin.ModelAdmin):
list_display = ('nome','data_nascimento')
admin.site.register(Paciente, PacienteAdmin)
7) Edit the file Settings.py to add myapp, then the INSTALLED_APPS section should look like this:
INSTALLED_APPS = [
'myapp',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
After these steps, run the project with runserver, enter admin, create a group and a user, give permission for the user to include but not to delete patients. If I made no mistake posting here and Voce followed all the steps correctly, the result will be as expected.
Obs.:
The example expressed here has been tested (and approved :-)) in a Linux environment.
Many thanks, solved the problem, I ended up creating another project and made the steps to check where the error was.
– Thay Gomes