lqez / django-summernote

Simply integrate Summernote editor with Django project.
MIT License
1.05k stars 227 forks source link

Problem with summernote in admin inlines #393

Open tobiasgardner opened 4 years ago

tobiasgardner commented 4 years ago

Using summernote works fine for none-inline models but as soon as I try to use it with inline-models, I get an error. There is some sourcecode and stacktrace available in the link below. I have tried with the normal admin as well as with grappelli, same result. I am using python 3.7.1, django 2.2.11 and django-summernote 0.8.11.6

# admin.py
from django.contrib import admin
from django_summernote.admin import SummernoteModelAdmin, SummernoteInlineModelAdmin
from .models import *

# This will work...
class ProductDescriptionInline(admin.TabularInline):
    model = ProductDescription
    fields = ('language', 'machine_translation', 'name', 'excerpt', 'content', )

# This will not work...
class ProductDescriptionInline(SummernoteInlineModelAdmin):
    model = ProductDescription
    fields = ('language', 'machine_translation', 'name', 'excerpt', 'content', )
    summernote_fields = ('content', )

# Summernote is working in this context...
class ProductAdmin(SummernoteModelAdmin):
    list_display = ('sku', 'name', 'needs_attention_comments', )
    fields = ('sku', 'name', 'needs_attention_comments', )
    summernote_fields = ('needs_attention_comments', )

    inlines = (ProductDescriptionInline, )
#stacktrace
Internal Server Error: /admin/catalog/product/1914/change/
Traceback (most recent call last):
  File "...myproj\.venv37\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "...myproj\.venv37\lib\site-packages\django\core\handlers\base.py", line 145, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "...myproj\.venv37\lib\site-packages\django\core\handlers\base.py", line 143, in _get_response
    response = response.render()
  File "...myproj\.venv37\lib\site-packages\django\template\response.py", line 106, in render
    self.content = self.rendered_content
  File "...myproj\.venv37\lib\site-packages\django\template\response.py", line 83, in rendered_content
    content = template.render(context, self._request)
  File "...myproj\.venv37\lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 171, in render
    return self._render(context)
  File "...myproj\.venv37\lib\site-packages\django\test\utils.py", line 96, in instrumented_test_render
    return self.nodelist.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "...myproj\.venv37\lib\site-packages\django\test\utils.py", line 96, in instrumented_test_render
    return self.nodelist.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "...myproj\.venv37\lib\site-packages\django\test\utils.py", line 96, in instrumented_test_render
    return self.nodelist.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\defaulttags.py", line 209, in render
    nodelist.append(node.render_annotated(context))
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\loader_tags.py", line 176, in render
    template = context.template.engine.get_template(template_name)
  File "...myproj\.venv37\lib\site-packages\django\template\engine.py", line 143, in get_template
    template, origin = self.find_template(template_name)
  File "...myproj\.venv37\lib\site-packages\django\template\engine.py", line 125, in find_template
    template = loader.get_template(name, skip=skip)
  File "...myproj\.venv37\lib\site-packages\django\template\loaders\base.py", line 18, in get_template
    for origin in self.get_template_sources(template_name):
  File "...myproj\.venv37\lib\site-packages\django\template\loaders\filesystem.py", line 36, in get_template_sources
    name = safe_join(template_dir, template_name)
  File "...myproj\.venv37\lib\site-packages\django\utils\_os.py", line 32, in safe_join
    final_path = abspath(join(base, *paths))
  File "C:\Program Files (x86)\Python\Python37\lib\ntpath.py", line 115, in join
    genericpath._check_arg_types('join', path, *paths)
  File "C:\Program Files (x86)\Python\Python37\lib\genericpath.py", line 149, in _check_arg_types
    (funcname, s.__class__.__name__)) from None
TypeError: join() argument must be str or bytes, not 'NoneType'
Internal Server Error: /admin/catalog/product/1914/change/
Traceback (most recent call last):
  File "...myproj\.venv37\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "...myproj\.venv37\lib\site-packages\django\core\handlers\base.py", line 145, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "...myproj\.venv37\lib\site-packages\django\core\handlers\base.py", line 143, in _get_response
    response = response.render()
  File "...myproj\.venv37\lib\site-packages\django\template\response.py", line 106, in render
    self.content = self.rendered_content
  File "...myproj\.venv37\lib\site-packages\django\template\response.py", line 83, in rendered_content
    content = template.render(context, self._request)
  File "...myproj\.venv37\lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 171, in render
    return self._render(context)
  File "...myproj\.venv37\lib\site-packages\django\test\utils.py", line 96, in instrumented_test_render
    return self.nodelist.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "...myproj\.venv37\lib\site-packages\django\test\utils.py", line 96, in instrumented_test_render
    return self.nodelist.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "...myproj\.venv37\lib\site-packages\django\test\utils.py", line 96, in instrumented_test_render
    return self.nodelist.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 937, in render
    bit = node.render_annotated(context)
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\defaulttags.py", line 209, in render
    nodelist.append(node.render_annotated(context))
  File "...myproj\.venv37\lib\site-packages\django\template\base.py", line 904, in render_annotated
    return self.render(context)
  File "...myproj\.venv37\lib\site-packages\django\template\loader_tags.py", line 176, in render
    template = context.template.engine.get_template(template_name)
  File "...myproj\.venv37\lib\site-packages\django\template\engine.py", line 143, in get_template
    template, origin = self.find_template(template_name)
  File "...myproj\.venv37\lib\site-packages\django\template\engine.py", line 125, in find_template
    template = loader.get_template(name, skip=skip)
  File "...myproj\.venv37\lib\site-packages\django\template\loaders\base.py", line 18, in get_template
    for origin in self.get_template_sources(template_name):
  File "...myproj\.venv37\lib\site-packages\django\template\loaders\filesystem.py", line 36, in get_template_sources
    name = safe_join(template_dir, template_name)
  File "...myproj\.venv37\lib\site-packages\django\utils\_os.py", line 32, in safe_join
    final_path = abspath(join(base, *paths))
  File "C:\Program Files (x86)\Python\Python37\lib\ntpath.py", line 115, in join
    genericpath._check_arg_types('join', path, *paths)
  File "C:\Program Files (x86)\Python\Python37\lib\genericpath.py", line 149, in _check_arg_types
    (funcname, s.__class__.__name__)) from None
TypeError: join() argument must be str or bytes, not 'NoneType'
[17/Mar/2020 19:24:13] "GET /admin/catalog/product/1914/change/ HTTP/1.1" 500 382221
dduraipandian commented 4 years ago

AdminB InlineModelAdmin is designed for to integrate with AdminA models like editing colums of the given AdminA.

class InlineModelAdmin(BaseModelAdmin):
    """
    Options for inline editing of ``model`` instances.

    Provide ``fk_name`` to specify the attribute name of the ``ForeignKey``
    from ``model`` to its parent. This is required if ``model`` has more than
    one ``ForeignKey`` to its parent.
    """

Other works because, template is already defined admin.

class TabularInline(InlineModelAdmin):
    template = 'admin/edit_inline/tabular.html'

I hope this will help you.

tobiasgardner commented 4 years ago

Thanks for the answer dduraipandian! Not sure if it helps though. To me it seems like a generic answer on how Inlines works in Django, is that correct? My problem was that I could not get summernote to work with inline models.

dduraipandian commented 4 years ago

Please StackedInline. Hope this works for you.

class ProductDescriptionInline(SummernoteModelAdminMixin, admin.StackedInline):
    model = ProductDescription
    fields = ('language', 'machine_translation', 'name', 'excerpt', 'content', )
    summernote_fields = ('content', )

class ProductAdmin(SummernoteModelAdmin):
    list_display = ('sku', 'name', 'needs_attention_comments', )
    fields = ('sku', 'name', 'needs_attention_comments', )
    summernote_fields = ('needs_attention_comments', )

    inlines = (ProductDescriptionInline, )