This file contains hidden or 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
| # Example usage of database funtions(`Sum` and `Avg`) and Django `JSONField`'s `jsonb_array_length` | |
| # PostgreSQL json field functions: https://www.postgresql.org/docs/9.5/static/functions-json.html | |
| # Django `F` and `Func`: https://docs.djangoproject.com/en/1.10/ref/models/expressions/#f-expressions | |
| # Django aggregation: https://docs.djangoproject.com/en/1.10/topics/db/aggregation/ | |
| # Django `JSONField`: https://docs.djangoproject.com/en/1.9/ref/contrib/postgres/fields/#jsonfield | |
| # Given a model | |
| class Contact(models.Model): | |
| numbers = JSONField(help_text="An array of numbers") |
This file contains hidden or 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
| # Thanks to Ethan Jucovy | |
| # http://www.coactivate.org/projects/ejucovy/blog/2014/05/10/wagtail-notes-managing-redirects-as-pages/ | |
| # This model comes from wagtaildemo | |
| class LinkFields(models.Model): | |
| link_external = models.URLField("External link", blank=True) | |
| link_page = models.ForeignKey( | |
| 'wagtailcore.Page', | |
| null=True, |
This file contains hidden or 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.conf import settings | |
| from django.utils.safestring import mark_safe | |
| from wagtail.wagtailadmin.edit_handlers import BaseFieldPanel | |
| class BaseColorFieldPanel(BaseFieldPanel): | |
| def render_js(self): | |
| big_javascript_block = """ | |
| (function() { |
This file contains hidden or 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
| import base64 | |
| from django import forms | |
| from django.core.files.uploadedfile import SimpleUploadedFile | |
| class Base64MultiField(forms.MultiValueField): | |
| def __init__(self, *args, **kwargs): | |
| kwargs['fields'] = ( | |
| forms.CharField(), |