Django without model visualization in the common user admin even having permissions and being in the same group

0

Good afternoon, So I am trying to give permissions that already comes in django to an ordinary user who even belonging to the group can not access the models that is granted to it. Someone had this problem of not viewing models in admin. version of python 2.7 and django 1.10

I already have the conf settings like 'django.contrib.auth', 'django.contrib.auth.middleware.AuthenticationMiddleware'

no models I have only:

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"

And in the admin I have:

class PacienteAdmin(ModelAdmin):
    list_display = ('nome','data_nascimento')

admin.site.register(Paciente, PacienteAdmin)

Just this and still without visualization of it. Thank you in advance.

    
asked by anonymous 03.03.2017 / 19:02

1 answer

0

I ran a test with your code and it works perfectly, the only error I see in the code that 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 does not work, try following 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)Editthemodels.pyfileinthemyappdirectorytolooklikethis:

fromdjango.dbimportmodelsclassPaciente(models.Model):nome=models.CharField(max_length=60)data_nascimento=models.DateField()def__str__(self):returnself.nomeclassMeta:verbose_name="Paciente"
        verbose_name_plural = "Pacientes"

6) Edit the admin file in myapp, so that 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 settings.py file 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 can not delete patients. If I did not make any mistakes when posting here and you followed all the steps correctly, the result will be expected.

Note: The example expressed here has been tested (and approved :-)) in a Linux environment.

    
04.03.2017 / 20:39