{ "info": { "author": "Mikalai Radchuk", "author_email": "mikalai.radchuk@torchbox.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 2.0", "Framework :: Django :: 2.1", "Framework :: Django :: 2.2", "Framework :: Wagtail :: 2", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Internet :: WWW/HTTP :: Site Management" ], "description": "# [wagtailmedia](https://pypi.org/project/wagtailmedia/) [](https://pypi.org/project/wagtailmedia/) [](https://travis-ci.org/torchbox/wagtailmedia)\n\nA module for Wagtail that provides functionality similar to `wagtail.documents` module,\nbut for audio and video files.\n\n## Compatibility\n\n`wagtailmedia` is compatible with Wagtail 2.2 and above. For compatibility with Wagtail 2.1 and 2.0, use the [v0.2.0 release](https://pypi.org/project/wagtailmedia/0.2.0/).\n\n## How to install\n\nInstall using pip:\n\n```sh\npip install wagtailmedia\n```\n\n### Settings\n\nIn your settings file, add `wagtailmedia` to `INSTALLED_APPS`:\n\n```python\nINSTALLED_APPS = [\n # ...\n 'wagtailmedia',\n # ...\n]\n```\n\n### URL configuration\n\nYour project needs to be set up to serve user-uploaded files from `MEDIA_ROOT`.\nYour Django project may already have this in place, but if not, add the following snippet to `urls.py`:\n\n```python\nfrom django.conf import settings\nfrom django.conf.urls.static import static\n\nurlpatterns = [\n # ... the rest of your URLconf goes here ...\n] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)\n```\n\nNote that this only works in development mode (`DEBUG = True`);\nin production, you will need to configure your web server to serve files from `MEDIA_ROOT`.\nFor further details, see the Django documentation: [Serving files uploaded by a user during development](https://docs.djangoproject.com/en/stable/howto/static-files/#serving-files-uploaded-by-a-user-during-development)\nand [Deploying static files](https://docs.djangoproject.com/en/stable/howto/static-files/deployment/).\n\nWith this configuration in place, you are ready to run `./manage.py migrate` to create the database tables used by wagtailmedia.\n\n### Custom `Media` model\n\nThe `Media` model can be customised. To do this, you need\nto add a new model to your project that inherits from `wagtailmedia.models.AbstractMedia`.\n\nThen set the `WAGTAILMEDIA_MEDIA_MODEL` setting to point to it:\n\n```python\nWAGTAILMEDIA_MEDIA_MODEL = 'mymedia.CustomMedia'\n```\n\n## How to use\n\n### As a regular Django field\n\nYou can use `Media` as a regular Django field. Here\u2019s an example:\n\n```python\nfrom __future__ import unicode_literals\n\nfrom django.db import models\n\nfrom wagtail.wagtailcore.models import Page\nfrom wagtail.wagtailcore.fields import RichTextField\nfrom wagtail.wagtailadmin.edit_handlers import FieldPanel\n\nfrom wagtailmedia.edit_handlers import MediaChooserPanel\n\n\nclass BlogPageWithMedia(Page):\n author = models.CharField(max_length=255)\n date = models.DateField(\"Post date\")\n body = RichTextField(blank=False)\n featured_media = models.ForeignKey(\n 'wagtailmedia.Media',\n null=True,\n blank=True,\n on_delete=models.SET_NULL,\n related_name='+'\n )\n\n content_panels = Page.content_panels + [\n FieldPanel('author'),\n FieldPanel('date'),\n FieldPanel('body'),\n MediaChooserPanel('featured_media'),\n ]\n```\n\n#### Name clash with Wagtail\n\nDo not name the field `media`. When rendering the admin UI, Wagtail uses a `media` property for its fields\u2019 CSS & JS assets loading. Using `media` as a field name breaks the admin UI ([#54](https://github.com/torchbox/wagtailmedia/issues/54)).\n\n### In StreamField\n\nYou can use `Media` in StreamField. To do this, you need\nto add a new block class that inherits from `wagtailmedia.blocks.AbstractMediaChooserBlock`\nand implement your own `render_basic` method.\n\nHere is an example:\n\n```python\nfrom __future__ import unicode_literals\n\nfrom django.db import models\nfrom django.utils.html import format_html\n\nfrom wagtail.wagtailcore.models import Page\nfrom wagtail.wagtailcore.fields import StreamField\nfrom wagtail.wagtailcore import blocks\nfrom wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel\n\nfrom wagtailmedia.blocks import AbstractMediaChooserBlock\n\n\nclass TestMediaBlock(AbstractMediaChooserBlock):\n def render_basic(self, value, context=None):\n if not value:\n return ''\n\n if value.type == 'video':\n player_code = '''\n