You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I feel like the intent of the presave signal isn't to raise an exception when instance.article is None.
@disable_signal_for_loaddatadefon_reusable_plugin_pre_save(**kwargs):
# Automatically make the original article the first one in the added# setinstance=kwargs["instance"]
ifnotinstance.article: # <---- Raise a RelatedObjectDoesNotExist exceptionarticles=instance.articles.all()
ifarticles.exists():
instance.article=articles[0]
My guess is the following part in ReusablePlugin class didn't do anything or not anymore.
# The article on which the plugin was originally created.# Used to apply permissions.ArticlePlugin.article.on_delete=models.SET_NULLArticlePlugin.article.verbose_name=_("original article")
ArticlePlugin.article.help_text=_("Permissions are inherited from this article")
ArticlePlugin.article.null=TrueArticlePlugin.article.blank=True
According to the django documentation you cannot modified inherited fields without a proper abstract class, so the ReusablePlugin.article cannot be different than ArticlePlugin.article
I dont know how much of a hindrance it is for attachment plugin but we should either :
remove the part of the code that threat ReusablePlugin.article as if it has null==blank==True
make ArticlePlugin class abstract (with database change)
remove the inheritance of ReusablePlugin from ArticlePlugin (with database change)
keep in mind that it also mean that on_delete==models.CASCADE and if we keep the current code the feature "the attachment isnt deleted when the main Article is deleted" didnt work as intended i assume.
The text was updated successfully, but these errors were encountered:
I can imagine that forcing an article relation on a plugin is intended to ensure that a ArticlePlugin/ReusablePlugin instance is always associated with some Article.
What is the case that ReusablePlugin should satisfy when it has no article relations? Is it so that it keeps existing despite all usage (relations) being removed?
Maybe the easiest way is to create a new base abstract model, ReusableNullablePlugin and then refactor ReusablePlugin and ArticlePlugin so that a new abstract base class with everything except the non-nullable article fk field is created and inherited from and the nullable/not-nullable article fk is then explicit on the base models themselves? This way, no migrations and changes would be necessary for existing usage.
I started to make test for models.baseplugins.py but I came across a problem
I feel like the intent of the presave signal isn't to raise an exception when
instance.article
is None.My guess is the following part in
ReusablePlugin
class didn't do anything or not anymore.According to the django documentation you cannot modified inherited fields without a proper abstract class, so the
ReusablePlugin.article
cannot be different thanArticlePlugin.article
I dont know how much of a hindrance it is for attachment plugin but we should either :
ReusablePlugin.article
as if it hasnull==blank==True
ArticlePlugin
class abstract (with database change)ReusablePlugin
fromArticlePlugin
(with database change)keep in mind that it also mean that
on_delete==models.CASCADE
and if we keep the current code the feature "the attachment isnt deleted when the main Article is deleted" didnt work as intended i assume.The text was updated successfully, but these errors were encountered: