2

I have been whriten API for my app. End when I to start servver terminal cought this: File "/home/user/MyProjects/forest-venv/forest/logginsite/admin.py", line 11, in class LScharacteristicAdmin(DynamicRawIDMixin): File "/home/user/MyProjects/forest-venv/lib/python3.5/site-packages/django/contrib/admin/decorators.py", line 25, in _model_admin_wrapper raise ValueError('Wrapped class must subclass ModelAdmin.) ValueError: Wrapped class must subclass ModelAdmin. `I'm new with django... How to fix that?

Are depended part of my project:

admin.py:

from django.contrib.gis import admin
from .models import *
from dynamic_raw_id.admin import DynamicRawIDMixin

class DefaultGeoAdmin(admin.OSMGeoAdmin):
    search_fields = ['code', 'name']
    display_wkt = True
    save_on_top = True

@admin.register(LScharacteristic)
class LScharacteristicAdmin(DynamicRawIDMixin):
    list_display = ('code', 'codeLS', 'track', 'task','totalarea','explarea','protecttype' )
    dynamic_raw_id_fields = ('codeLS', )
    model = LScharacteristic

models.py:

    from django.db import models
    from django.utils.translation import ugettext_lazy as _
    from renter.models import RefAbstract, Renter
    from django.contrib.gis.db import models

    class Unit(RefAbstract):
        class Meta(RefAbstract.Meta):
            verbose_name = 'nameunit'
            verbose_name_plural = 'namesofunits'
    
    class ManageType(RefAbstract):
        class Meta(RefAbstract.Meta):
            verbose_name = 'type'
            verbose_name_plural = 'types'
    
    class CutareaShape(RefAbstract):
        class Meta(RefAbstract.Meta):
            verbose_name = 'cut'
            verbose_name_plural = 'cuts'
            
    class CutareaType(models.Model):
        name = models.TextField('name', max_length=500)
        
        def __str__(self):
            return shorten(self.name, width=60)
        
        class Meta:
            verbose_name = 'cut2'
            verbose_name_plural = 'cuts2'
    
    class Composition(RefAbstract):
        class Meta(RefAbstract.Meta):
            verbose_name = 'set'
            verbose_name_plural = 'sets'
    
    class Assortment(RefAbstract):
        class Meta(RefAbstract.Meta):
            verbose_name = 'assort'
            verbose_name_plural = 'assorts'
    class CodeLS(RefAbstract):
        class Meta(RefAbstract.Meta):
            verbose_name = 'area'
            verbose_name_plural = 'areas'
    
    class LScharacteristic(models.Model):
        code = models.IntegerField( help_text='number')
        codeLS = models.ForeignKey(CodeLS, on_delete=models.DO_NOTHING, verbose_name='id area')           
        task = models.CharField(max_length = 100, help_text ='task')
        totalrea = models.PositiveIntegerField(help_text = 'totarea')
        explarea = models.PositiveIntegerField(help_text = 'explarea')
        protecttype = models.CharField(max_length = 50, help_text = 'protecttype')
    
class PlannedUsing(models.Model):
        #...some variables
        
class Spatial(models.Model):
        #...some variables
    

I don't understand why django throw it. This admin.py file was created like another admin.py, witch will work in app.

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Tyomik_mnemonic
  • 786
  • 3
  • 9
  • 31
  • 2
    please show us some code (just the relevant part(s)), and the full traceback of the error – Robin Zigmond Jan 29 '19 at 09:25
  • @RobinZigmond sorry! I thought that this error is something the a certain. I added code now – Tyomik_mnemonic Jan 29 '19 at 09:56
  • 1
    I just had a glance at the plugin you're using: https://github.com/lincolnloop/django-dynamic-raw-id/blob/master/README.rst - I'm not familiar with it, but it appears to me that your error is not inheriting from `admin.ModelAdmin` in the class you're decorating. Try `class LScharacteristicAdmin(admin.ModelAdmin, DynamicRawIDMixin):` instead – Robin Zigmond Jan 29 '19 at 10:01

2 Answers2

2

The problem lies here class LScharacteristicAdmin(DynamicRawIDMixin)

it should be inheriting from admin.ModelAdmin so rewrite it like this

class LScharacteristicAdmin(admin.ModelAdmin)

Hopefully, that should solve the error you are getting

TarangP
  • 2,711
  • 5
  • 20
  • 41
Micheal N.D
  • 410
  • 5
  • 8
0

I got the same error:

ValueError: Wrapped class must subclass ModelAdmin.

When putting admin.TabularInline or admin.StackedInline for the admin registration as shown below:

from django.contrib import admin
from .models import Person

@admin.register(Person) # ↓ Here
class PersonAdmin(admin.TabularInline):
    pass
from django.contrib import admin
from .models import Person

@admin.register(Person) # ↓ Here
class PersonAdmin(admin.StackedInline):
    pass

So, I replaced them with admin.ModelAdmin as shown below, then the error was solved:

from django.contrib import admin
from .models import Person

@admin.register(Person) # ↓ Here
class PersonAdmin(admin.ModelAdmin):
    pass
from django.contrib import admin
from .models import Person

@admin.register(Person) # ↓ Here
class PersonAdmin(admin.ModelAdmin):
    pass
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129