Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaDefiningClass Object is not iterable ?

Trying to use Inlines to get customised view at Admin Dashboard. Below is the code

from django.contrib import admin # noqa
from oscar.core.loading import get_model
from oscar.apps.catalogue.admin import *

CategoryAttribute = get_model('catalogue', 'CategoryAttribute')
CategoryAttributeValue = get_model('catalogue', 'CategoryAttributeValue')
Category = get_model('catalogue', 'Category')

class CategoryAttributeInline(admin.TabularInline):
    model = CategoryAttributeValue
    fk_name = 'category'
    extra = 1

class CategoryAdmin(admin.ModelAdmin):
    inlines = [CategoryAttributeInline,]

admin.site.register(CategoryAttributeValue)
admin.site.register(CategoryAttribute)
admin.site.register(Category, CategoryAdmin)

The error I am getting is TypeError: 'MediaDefiningClass' object is not iterable

What is the problem in my code ?

like image 600
Coderaemon Avatar asked Sep 27 '22 00:09

Coderaemon


1 Answers

sometimes the cause of this error was sending arguments to the register function in the wrong order.

Check the order of registering a ModelAdmin: it’s the model class first, then the ModelAdmin class.

Example: admin.site.register(Model, ModelAdmin)

I suppose naturally the second one has to be the ModelAdmin since register(MyModel) works as well.

like image 180
Adi Ep Avatar answered Oct 04 '22 19:10

Adi Ep