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
Found a bug? Please fill out the sections below. 👍
Issue Summary
Imagine a drip email marketing functionality, in which non-developers are able to build query sets from dropdown menus and append them as inline panels on an email form. That's what this is ;). Of course, people tend to forget things, and the first thing that needs to be included in an email marketing rule by default which the content author would otherwise forget is to exclude people who have unsubscribed. So this is an attempt to automatically append "is_subscribed = True" to the first inline rule of a marketing email form.
But, the conditional default modeladmin inline property seems to be duplicated under certain circumstances. When defining a custom CreateView with an inline form pre-filled, the form is properly appended upon create. But upon edit of the just-created item, the item seems to have been duplicated, there are then two identical entries.
After removing one of the duplicates and saving the item, the duplicate doesn't come back a second time after going back and forth between the edit/list page, so this seems to be specific to the initial create + save, perhaps, in the CreateView that was specified.
Migrate, integrate the drip admin into wagtail via wagtail_hooks like so....
(You will of course not have an is_subscribed boolean field, change to some other django user model boolean field to see the result, you'll also not have the django-summernote editor widget unless you install it. Otherwise I think these should work as described.)
So the conditionals seem to be working as expected.
This doesn't appear to be some weird browser caching behavior, the database shows two identical entries for the first inline, here's an SQL dump of one after 'create':
Hi @awhileback,
I think this is because the queryset_rules relation in django-drip-campaigns - being not specifically built for Wagtail - is a ForeignKey rather than a ParentalKey. InlinePanels are only designed for ParentalKey relations - these have different behaviours regarding how forms are processed and the order in which models are saved, and these differences are key to various bits of Wagtail functionality like previewing and revision history.
Having said that, those aspects don't apply to ModelAdmin, and since ModelAdmin is intended to work with plain Django models, I think it's reasonable to expect plain foreign keys to work there. So while I don't think this is an actual bug, I'd say it's a legitimate feature request.
gasman
changed the title
modeladmin CreateView set to conditionally pre-populate an inline panel produces duplicate inlines upon create, but not thereafter.
Ability to use plain ForeignKeys with InlinePanels in modeladmin
Jun 4, 2021
Hey @gasman, thanks for the reply, now that you mention it I remember why there was a need to fork the drip app. Sorry, it's been awhile since I got this working initially a couple of years ago, I've just come back to it for the purpose of upgrading versions.
I did sub-class the InlinePanel model and change it to a ParentalKey to get it to work. That was done before I posted the bug report.
Found a bug? Please fill out the sections below. 👍
Issue Summary
Imagine a drip email marketing functionality, in which non-developers are able to build query sets from dropdown menus and append them as inline panels on an email form. That's what this is ;). Of course, people tend to forget things, and the first thing that needs to be included in an email marketing rule by default which the content author would otherwise forget is to exclude people who have unsubscribed. So this is an attempt to automatically append "is_subscribed = True" to the first inline rule of a marketing email form.
But, the conditional default modeladmin inline property seems to be duplicated under certain circumstances. When defining a custom
CreateView
with an inline form pre-filled, the form is properly appended upon create. But upon edit of the just-created item, the item seems to have been duplicated, there are then two identical entries.After removing one of the duplicates and saving the item, the duplicate doesn't come back a second time after going back and forth between the edit/list page, so this seems to be specific to the initial create + save, perhaps, in the
CreateView
that was specified.Steps to Reproduce
wagtail_hooks
like so....(You will of course not have an
is_subscribed
boolean field, change to some other django user model boolean field to see the result, you'll also not have the django-summernote editor widget unless you install it. Otherwise I think these should work as described.)To further test this I put some print statements in my conditionals along with an
EditView
specification and got the following...Upon edit, I get...
Upon create, with a print of
('false')
added to the default inline...I got...
So the conditionals seem to be working as expected.
This doesn't appear to be some weird browser caching behavior, the database shows two identical entries for the first inline, here's an SQL dump of one after 'create':
Technical details
The text was updated successfully, but these errors were encountered: