{ "info": { "author": "Yury Lapshinov", "author_email": "y.raagin@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Django StreamField\n\nThis is a simple realisation of StreamField's idea of Wagtail CMS for plain Django admin or with Grappelli skin.\n\n## Highlights\nYou can build your page with different kind of blocks. \nSort them and sort the lists inside the blocks.\n\nFor editing content inside the blocks, it use native popup mechanism in Django admin interface.\nThis allow you to use other field's widgets inside the blocks as is.\nFor example, if you want to use in your blocks FileBrowseField\nfrom django-filebrowser, it will perfectly working \nwithout any additional settings.\n\nModule also working with [Grappelli Interface](https://github.com/sehmaschine/django-grappelli) (Optional)\n\n\n\n## Contents\n\n- [Installation](#installation)\n- [How to use](#how-to-use)\n- [Admin](#admin)\n - [Custom admin class for block's models](#custom-admin-class-for-blocks-models)\n - [Custom templates for render block models in admin](#custom-templates-for-render-block-models-in-admin)\n - [Override how to render block's fields in admin](#override-how-to-render-blocks-fields-in-admin)\n - [Override list of blocks for your StreamField in admin.py](#override-list-of-blocks-for-your-streamfield-in-adminpy)\n- [Block options](#block-options)\n- [Special cases](#special-cases)\n - [Complex Blocks](#complex-blocks) \n - [Blocks without data in database. Only templates](#blocks-without-data-in-database-only-templates)\n - [Add extra context to blocks](#add-extra-context-to-blocks)\n - [Cache for reduce the number of database requests](#cache-for-reduce-the-number-of-database-requests)\n- [Settings](#settings)\n\n## Installation\n\nRequirements: `django>=2.*`\n\n`pip install django-streamfield`\n\n## How to use\n\n**1. Create new app called `streamblocks`**\n\n**2. Put to `streamblocks/models.py` some models**\n\n...that you want to use in your stream field.\nAnd add this models in STREAMBLOCKS_MODELS list.\nFor example:\n\n```python\n# streamblocks/models.py\n\n# one object\nclass RichText(models.Model):\n text = models.TextField(blank=True, null=True) \n\n class Meta:\n # This will use as name of block in admin\n verbose_name=\"Text\"\n\n# list of objects\nclass ImageWithText(models.Model):\n image = models.ImageField(upload_to=\"folder/\")\n text = models.TextField(null=True, blank=True)\n\n # StreamField option for list of objects\n as_list = True\n\n class Meta:\n verbose_name=\"Images with text\"\n\n# Register blocks for StreamField as list of models\nSTREAMBLOCKS_MODELS = [\n RichText,\n ImageWithText\n]\n```\n\n**3. Create templates for each models above, named as lowercase names of the models:**\n\n1. streamblocks/templates/streamblocks/richtext.html\n2. streamblocks/templates/streamblocks/imagewithtext.html\n\nAnd use `block_content` as context.\n\n> Note: block_content will be single object \nif no 'as_list' property in your model, \nand will be a list of objects if there is.\n\n```html\n\n
{{ block.text }}
\n