0

Tengo el siguiente error al acceder al modelo "Norma" a través del administrador django. "missing 1 required keyword-only argument: 'manager'"

El error completo es el siguiente:

Internal Server Error: /admin/norma/norma/
Traceback (most recent call last):
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\contrib\admin\utils.py", line 278, in lookup_field
    f = _get_non_gfk_field(opts, name)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\contrib\admin\utils.py", line 313, in _get_non_gfk_field
    raise FieldDoesNotExist()
django.core.exceptions.FieldDoesNotExist

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\core\handlers\base.py", line 156, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\core\handlers\base.py", line 154, in _get_response
    response = response.render()
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\response.py", line 106, in render
    self.content = self.rendered_content
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\response.py", line 83, in rendered_content
    content = template.render(context, self._request)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 171, in render
    return self._render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\contrib\admin\templatetags\base.py", line 33, in render
    return super().render(context)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\template\library.py", line 214, in render
    _dict = self.func(*resolved_args, **resolved_kwargs)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\contrib\admin\templatetags\admin_list.py", line 341, in result_list
    'results': list(results(cl))}
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\contrib\admin\templatetags\admin_list.py", line 318, in results
    yield ResultList(None, items_for_result(cl, res, None))
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\contrib\admin\templatetags\admin_list.py", line 309, in __init__
    super().__init__(*items)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\contrib\admin\templatetags\admin_list.py", line 228, in items_for_result
    f, attr, value = lookup_field(field_name, result, cl.model_admin)
  File "C:\Users\Acevedo Duran\Documents\Desarrollos\PT2\Competence Check 001\virtualenv\lib\site-packages\django\contrib\admin\utils.py", line 291, in lookup_field
    value = attr()
TypeError: __call__() missing 1 required keyword-only argument: 'manager'

models.py

from django.db import models
from app.eje_curricular.models import Eje_curricular
from app.taxonomia.models import Taxonomia

# Create your models here.

class Norma(models.Model):
    nombre = models.CharField(max_length=100)
    abreviatura = models.CharField(max_length=5, null=True, blank=True)
    organizacion = models.CharField(max_length=100, null=True, blank=True)
    descripcion = models.TextField(null=True, blank=True)
    activa_en_eje = models.BooleanField(default=False)
    eje = models.ForeignKey(Eje_curricular, related_name='normas' ,on_delete=models.SET_NULL, null=True, blank=True)
    taxonomia = models.OneToOneField(Taxonomia, related_name='norma' ,on_delete=models.SET_NULL, null=True)

    timestamp = models.DateTimeField(auto_now_add=True, auto_now=False, null=True)
    lastModification = models.DateTimeField(auto_now_add=False, auto_now=True, null=True)
    def __str__(self):
        return self.nombre

    def __unicode__(self):
        return self.nombre

views.py

from django.shortcuts import render
from rest_framework import generics
from django_filters.rest_framework import DjangoFilterBackend
import django_filters.rest_framework
from .models import *
from .serializers import *

# Create your views here.

class NormaList(generics.ListCreateAPIView):
    queryset = Norma.objects.all()
    serializer_class = NormaSerializer
    filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
    filter_fields = (
        'id',
        'nombre', 
        'abreviatura',
        'competencias', 
        'organizacion', 
        'descripcion',
        'taxonomia', 
        'eje' , 
        'timestamp', 
        'lastModification', 
        )

class NormaDetail(generics.RetrieveUpdateDestroyAPIView):
    queryset = Norma.objects.all()
    serializer_class = NormaSerializer

admin.py

from django.apps import AppConfig
from django.contrib import admin
from .models import *

# Register your models here.

class NormaAdmin(admin.ModelAdmin):
    list_display = (
        'nombre', 
        'abreviatura', 
        'organizacion', 
        'descripcion', 
        'taxonomia',
        'competencias',
        'activa_en_eje', 
        'eje' ,
        'timestamp', 
        'lastModification', 
        )
    class Meta:
        model = Norma
admin.site.register(Norma, NormaAdmin)

serializers.py

from rest_framework import serializers
from .models import Norma
from app.categoria.models import Categoria

class NormaSerializer(serializers.ModelSerializer):
    categorias = serializers.HyperlinkedRelatedField(
        many=True,
        read_only=True,
        view_name='categoria-detail'
    )
    class Meta:
        model = Norma
        fields = (
            'id',
            'nombre', 
            'abreviatura', 
            'organizacion', 
            'descripcion', 
            'categorias' ,
            'taxonomia',
            'competencias',
            'activa_en_eje', 
            'eje', 
            'timestamp', 
            'lastModification', 
            )

No muestra ningún error al hacer las migraciones, sólo al acceder al administrador del backend.

alguna idea? Gracias!

1 respuesta 1

1

Fué un problema con el campo "competencias" en la clase Admin, el modelo Competencia tiene una foránea al modelo Norma.

Lo solucioné al crear el "Inline" del modelo "Competencia".

from django.apps import AppConfig
from django.contrib import admin
from .models import *
from app.competencia.models import Competencia

# Register your models here.

class CompetenciaInline(admin.TabularInline):
    model = Competencia

class NormaAdmin(admin.ModelAdmin):
    list_display = (
        'nombre', 
        'abreviatura', 
        'organizacion', 
        'descripcion', 
        'taxonomia',
        # 'competencias',
        'activa_en_eje', 
        'eje' ,
        'timestamp', 
        'lastModification', 
        )
    # filter_horizontal = (
    #     'competencias',
    # )
    inlines = [CompetenciaInline]
    class Meta:
        model = Norma
admin.site.register(Norma, NormaAdmin)

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.