mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-28 18:44:50 +00:00
Get snippet type name from model, not content type (otherwise it returns 'Content type')
This commit is contained in:
parent
939ff0827b
commit
6a7a23364b
1 changed files with 12 additions and 8 deletions
|
|
@ -14,6 +14,7 @@ from .widgets import AdminSnippetChooser
|
|||
class BaseSnippetChooserPanel(BaseChooserPanel):
|
||||
object_type_name = 'item'
|
||||
|
||||
_target_model = None
|
||||
_target_content_type = None
|
||||
|
||||
@classmethod
|
||||
|
|
@ -22,23 +23,26 @@ class BaseSnippetChooserPanel(BaseChooserPanel):
|
|||
content_type=cls.target_content_type(), snippet_type_name=cls.get_snippet_type_name())}
|
||||
|
||||
@classmethod
|
||||
def target_content_type(cls):
|
||||
if cls._target_content_type is None:
|
||||
def target_model(cls):
|
||||
if cls._target_model is None:
|
||||
if cls.snippet_type:
|
||||
try:
|
||||
model = resolve_model_string(cls.snippet_type)
|
||||
cls._target_model = resolve_model_string(cls.snippet_type)
|
||||
except LookupError:
|
||||
raise ImproperlyConfigured("{0}.snippet_type must be of the form 'app_label.model_name', given {1!r}".format(
|
||||
cls.__name__, cls.snippet_type))
|
||||
except ValueError:
|
||||
raise ImproperlyConfigured("{0}.snippet_type refers to model {1!r} that has not been installed".format(
|
||||
cls.__name__, cls.snippet_type))
|
||||
|
||||
cls._target_content_type = ContentType.objects.get_for_model(model)
|
||||
else:
|
||||
target_model = cls.model._meta.get_field(cls.field_name).rel.to
|
||||
cls._target_content_type = ContentType.objects.get_for_model(target_model)
|
||||
cls._target_model = cls.model._meta.get_field(cls.field_name).rel.to
|
||||
|
||||
return cls._target_model
|
||||
|
||||
@classmethod
|
||||
def target_content_type(cls):
|
||||
if cls._target_content_type is None:
|
||||
cls._target_content_type = ContentType.objects.get_for_model(cls.target_model())
|
||||
return cls._target_content_type
|
||||
|
||||
def render_as_field(self):
|
||||
|
|
@ -51,7 +55,7 @@ class BaseSnippetChooserPanel(BaseChooserPanel):
|
|||
|
||||
@classmethod
|
||||
def get_snippet_type_name(cls):
|
||||
return force_text(cls.target_content_type()._meta.verbose_name)
|
||||
return force_text(cls.target_model()._meta.verbose_name)
|
||||
|
||||
|
||||
class SnippetChooserPanel(object):
|
||||
|
|
|
|||
Loading…
Reference in a new issue