Created
July 24, 2024 10:07
-
-
Save laymonage/8b7e2150de1bbb38cbf3a73058942d26 to your computer and use it in GitHub Desktop.
Wagtail upload-only document chooser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .views import upload_only_document_chooser_viewset | |
UploadOnlyDocumentChooserBlock = upload_only_document_chooser_viewset.get_block_class( | |
name="UploadOnlyDocumentChooserBlock", module_path="myapp.blocks" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from wagtail.fields import StreamField | |
from .blocks import UploadOnlyDocumentChooserBlock | |
class MyModel(models.Model) | |
body = StreamField([ | |
('document', UploadOnlyDocumentChooserBlock(), | |
# ... | |
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load i18n wagtailadmin_tags %} | |
{% include "wagtailadmin/shared/header.html" with title=page_title merged=1 subtitle=page_subtitle icon=header_icon %} | |
{{ creation_form.media.js }} | |
{{ creation_form.media.css }} | |
<div class="w-tabs" data-tabs data-tabs-disable-url> | |
<div class="w-tabs__wrapper w-overflow-hidden"> | |
<div role="tablist" class="w-tabs__list w-w-full"> | |
{% include 'wagtailadmin/shared/tabs/tab_nav_link.html' with tab_id=view.creation_tab_id title=creation_tab_label %} | |
</div> | |
</div> | |
<div class="tab-content"> | |
{% include view.creation_form_template_name %} | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from wagtail.documents import get_document_model_string | |
from wagtail.documents.views.chooser import DocumentChooserViewSet, DocumentChooseView | |
class UploadOnlyDocumentChooseView(DocumentChooseView): | |
template_name = "upload_only_chooser.html" | |
class UploadOnlyDocumentChooserViewSet(DocumentChooserViewSet): | |
choose_view_class = UploadOnlyDocumentChooseView | |
upload_only_document_chooser_viewset = UploadOnlyDocumentChooserViewSet( | |
"upload_only_document_chooser", | |
model=get_document_model_string(), | |
url_prefix="upload-only-document-chooser", | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from wagtail import hooks | |
from .views import upload_only_document_chooser_viewset | |
@hooks.register("register_admin_viewset") | |
def register_upload_only_document_chooser_viewset(): | |
return upload_only_document_chooser_viewset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment