Skip to content

Instantly share code, notes, and snippets.

@aubricus
Last active October 15, 2017 10:19
Show Gist options
  • Save aubricus/23217efdfe8a1a6539b2b873e4c1e665 to your computer and use it in GitHub Desktop.
Save aubricus/23217efdfe8a1a6539b2b873e4c1e665 to your computer and use it in GitHub Desktop.
De-Dupe / Return Draft DjangoCMS Plugin Instances
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "my_plugin_fk":
kwargs["queryset"] = models.MyPluginModel.objects.filter(
Q(placeholder__static_draft__isnull=False) |
Q(placeholder__page__publisher_is_draft=True)
)
return super().formfield_for_foreignkey(db_field, request, **kwargs)
@aubricus
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment