2
我從這個線程https://github.com/wagtail/wagtail/issues/2001鶺鴒定製文檔模型
,你可以自定義鶺鴒文檔模型,你可以將圖像模式,額外的字段添加到它理解。我找不到有關如何執行此操作的任何文檔。如果任何人有什麼建議,從哪裏開始這將是偉大的。我是新的w so,所以任何幫助非常感謝。
謝謝!
我從這個線程https://github.com/wagtail/wagtail/issues/2001鶺鴒定製文檔模型
,你可以自定義鶺鴒文檔模型,你可以將圖像模式,額外的字段添加到它理解。我找不到有關如何執行此操作的任何文檔。如果任何人有什麼建議,從哪裏開始這將是偉大的。我是新的w so,所以任何幫助非常感謝。
謝謝!
自定義文檔模型可以採用與custom image model類似的方式實現。要添加自己的文檔模型(我們稱之爲CustomDocument
),你應該做到以下幾點:
創建從wagtail.wagtaildocs.models.AbstractDocument
繼承的典範。應該是這樣的:
class CustomDocument(AbstractDocument):
# Add your custom model fields here
admin_form_fields = (
'title',
'file',
'collection',
'tags'
# Add your custom model fields into this list,
# if you want to display them in the Wagtail admin UI.
)
註冊一個post_delete
信號處理程序,以從磁盤中刪除文件,一旦文件記錄在數據庫中刪除。它應該是這樣的:
# Receive the post_delete signal and delete the file associated with the model instance.
@receiver(post_delete, sender=CustomDocument)
def document_delete(sender, instance, **kwargs):
# Pass false so FileField doesn't save the model.
instance.file.delete(False)
設置WAGTAILDOCS_DOCUMENT_MODEL
設置爲指向你的模型。例如:
`WAGTAILDOCS_DOCUMENT_MODEL = 'your_app_label.CustomDocument'`
那太好了,謝謝你 - 感謝您的迅速反應:-) – gbmillard