theatlantic / django-nested-admin

Django admin classes that allow for nested inlines
http://django-nested-admin.readthedocs.org/
Other
690 stars 97 forks source link

'MediaDefiningClass' object is not iterable #208

Closed nabil-ha closed 2 years ago

nabil-ha commented 2 years ago

Hey, To be clear about what I'm doing, I chose nested_admin because I need to make a Course object, inside it a Part object, ( Part one, two and so on ) and each Part obj will have a File object I get this error after opening an object of a model:


Internal Server Error: /admin/myapp/course/1/change/
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 616, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/contrib/admin/sites.py", line 232, in inner
    return view(request, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1660, in change_view
    return self.changeform_view(request, object_id, form_url, extra_context)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1540, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 1604, in _changeform_view
    formsets, inline_instances = self._create_formsets(request, obj, change=True)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/nested_admin/nested.py", line 336, in _create_formsets
    in orig_inline.get_inline_instances(request, obj)]
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/contrib/admin/options.py", line 598, in get_inline_instances
    for inline_class in self.get_inlines(request, obj):
TypeError: 'MediaDefiningClass' object is not iterable

my admin.py:


class ToFileInline(nested_admin.NestedStackedInline):
    model = [FileToPart]

class ToPartInline(nested_admin.NestedInlineModelAdmin):
    model = CoursePart
    inlines = [ToFileInline]

class CourseAdmin(nested_admin.NestedModelAdmin):
    model = Course
    inlines = [ToPartInline]

my models.py:


class Course(models.Model):
    # video = models.FileField(verbose_name="", null=True, upload_to='media')
    courseName = models.CharField(verbose_name="", max_length=20)
    category = models.ForeignKey(Category, verbose_name="", on_delete=models.SET_NULL, null=True)
    intro = models.CharField(verbose_name="", max_length=1000)
    skills = models.CharField(verbose_name="", max_length=1000)
    features = models.CharField(verbose_name="", max_length=1000)
    rate = models.FloatField(verbose_name="")
    class Meta:
        verbose_name = ""
        verbose_name_plural = ""

class CoursePart(models.Model):
    course = models.ForeignKey(Course, on_delete=models.CASCADE)
    name = models.CharField("", max_length=20)

class FileToPart(models.Model):
    coursePart = models.ForeignKey(CoursePart, on_delete=models.CASCADE)
    file = models.FileField(verbose_name="")
fdintino commented 2 years ago

Is this a duplicate of #206?

nabil-ha commented 2 years ago

Is this a duplicate of #206?

No

fdintino commented 2 years ago

But the issue seems to be the same, that you have the model defined as a list:

class ToFileInline(nested_admin.NestedStackedInline):
    model = [FileToPart]

when it should be:

class ToFileInline(nested_admin.NestedStackedInline):
    model = FileToPart
nabil-ha commented 2 years ago

Thanks, weirdly the same error happened again but with different name. Sorry for taking your time.