### Install Development Tools for Project (Shell) Source: https://github.com/leehanyeong/django-quill-editor/blob/master/README.md Installs development tools for code formatting and pre-commit hooks. Requires Homebrew on macOS. No specific inputs; outputs installed tools. For contributors; optional pre-commit install after brew installs. ```shell # black brew install black # pre-commit brew install pre-commit pre-commit install ``` -------------------------------- ### Django Quill Editor Configuration in settings.py Source: https://context7.com/leehanyeong/django-quill-editor/llms.txt Provides examples of how to configure django-quill editor settings in Django's settings.py file, including installed apps and various Quill editor configurations for different use cases. ```python # settings.py # Installed apps configuration INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_quill', # Add django_quill 'rest_framework', # Optional: for DRF integration # ... your apps ] # Quill editor configurations QUILL_CONFIGS = { 'default': { 'theme': 'snow', # or 'bubble' 'modules': { 'syntax': True, # Code syntax highlighting 'toolbar': [ [{'font': []}, {'header': []}, {'align': []}], ['bold', 'italic', 'underline', 'strike', 'blockquote'], [{'color': []}, {'background': []}], ['code-block', 'link', 'image', 'video'], ['clean'] ], 'imageCompressor': { 'quality': 0.8, # Image quality (0-1) 'maxWidth': 2000, # Max image width 'maxHeight': 2000, # Max image height 'imageType': 'image/jpeg', 'debug': False, 'suppressErrorLogging': True }, 'resize': { 'showSize': True, # Show image dimensions 'locale': {} } } }, 'simple': { 'theme': 'snow', 'modules': { 'toolbar': [ ['bold', 'italic'], ['link'] ] } }, 'advanced': { 'theme': 'snow', 'modules': { 'syntax': True, 'toolbar': [ [{'header': [1, 2, 3, 4, 5, 6, False]}], [{'font': []}], [{'size': ['small', False, 'large', 'huge']}], ['bold', 'italic', 'underline', 'strike'], [{'color': []}, {'background': []}], [{'script': 'sub'}, {'script': 'super'}], ['blockquote', 'code-block'], [{'list': 'ordered'}, {'list': 'bullet'}], [{'indent': '-1'}, {'indent': '+1'}], [{'align': []}], ['link', 'image', 'video', 'formula'], ['clean'] ] } } } ``` -------------------------------- ### Release Package to PyPI (Shell) Source: https://github.com/leehanyeong/django-quill-editor/blob/master/README.md Builds and deploys the package to PyPI using Poetry. Requires Poetry setup. Inputs: deploy.py script. Outputs published package. For package owners; run in project root. ```shell poetry install # Install PyPI distribution packages python deploy.py ``` -------------------------------- ### Install django-quill-editor using pip Source: https://github.com/leehanyeong/django-quill-editor/blob/master/docs/index.rst Instructions for installing the django-quill-editor package using pip. This is the standard method for adding Python packages to your project. ```bash pip install django-quill-editor ``` -------------------------------- ### Build Sphinx Documentation Locally (Shell) Source: https://github.com/leehanyeong/django-quill-editor/blob/master/README.md Builds and serves Sphinx documentation locally. Requires Sphinx installed via Homebrew. Inputs: docs directory. Outputs HTML docs served at localhost:3001. For doc maintainers; run in docs directory. ```shell brew install sphinx-doc # macOS cd docs make html # ... # The HTML pages are in _build/html. cd _build/html python -m http.server 3001 ``` -------------------------------- ### Template for Quill ModelForm Source: https://github.com/leehanyeong/django-quill-editor/blob/master/docs/pages/using-as-modelform.md This HTML template snippet demonstrates rendering a QuillPostForm in a Django template. The Quill editor is automatically rendered for the QuillField. ```html
``` -------------------------------- ### Display QuillFormField in Django Template Source: https://github.com/leehanyeong/django-quill-editor/blob/master/docs/pages/using-as-form.md Provides an example of how to render the form containing the QuillFormField within a Django template. This will display the rich text editor for user input. ```html ``` -------------------------------- ### Render Quill ModelForm in Django View Source: https://github.com/leehanyeong/django-quill-editor/blob/master/docs/pages/using-as-modelform.md This snippet shows how to pass a QuillPostForm to a template from a Django view, similar to handling regular forms. ```python from django.shortcuts import render from .forms import QuillPostForm def model_form_view(request): return render(request, 'form_view.html', {'form': QuillPostForm()}) ``` -------------------------------- ### Create Django ModelForm for QuillField Source: https://github.com/leehanyeong/django-quill-editor/blob/master/docs/pages/using-as-modelform.md This snippet demonstrates creating a ModelForm for a model containing a QuillField. The form automatically includes the Quill editor for the QuillField. ```python from django import forms from .models import QuillPost class QuillPostForm(forms.ModelForm): class Meta: model = QuillPost fields = ( 'content', ) ``` -------------------------------- ### Define Django Model with QuillField Source: https://github.com/leehanyeong/django-quill-editor/blob/master/docs/pages/rest-framework.md Example model definition using QuillField from django-quill-editor. This model serves as the base for storing rich text content that can be processed by Quill.js editor. The field stores both HTML and delta content for flexible frontend rendering. ```python from django_quill.fields import QuillField class QuillPost(models.Model): content = QuillField() ``` -------------------------------- ### Adding QuillField to Django Model Source: https://github.com/leehanyeong/django-quill-editor/blob/master/docs/pages/using-in-admin.md Import QuillField from django_quill.fields and use it in your model class to replace standard text fields for rich text support. This requires django-quill-editor to be installed and configured in settings. The field integrates with Django's ORM, accepting and storing HTML content without additional outputs specified. Limitations include potential storage overhead for rich content. ```python from django.db import models from django_quill.fields import QuillField class QuillPost(models.Model): content = QuillField() ``` -------------------------------- ### Run Local Demo Project (Shell) Source: https://github.com/leehanyeong/django-quill-editor/blob/master/README.md Clones and runs the django-quill-editor demo locally. Requires Git and Python venv. Inputs: Git repo URL and directory. Outputs running Django server at localhost:8000. Virtual environment recommended; demo site at localhost:8000. ```shell # [Optional] We recommend that you start after creating a folder for your project. mkdir ~/projects cd projects # Clone repository git clone git@github.com:LeeHanYeong/django-quill-editor.git # Go to the project directory and apply the virtual environment cd django-quill-editor # [apply venv] # Go to the playground package cd playground # Install requirements pip install -r requirements.txt # Run migrate and runserver python manage.py migrate python manage.py runserver ``` -------------------------------- ### Deploy with Docker Compose (Shell) Source: https://github.com/leehanyeong/django-quill-editor/blob/master/README.md Runs Docker Compose for local or production deployment. Requires Docker and env files. Inputs: env file path. Outputs running containers. Specify env file for local or production; force rebuilds orphans. ```shell # local docker-compose --env-file .deploy/.env.local up --build --force-recreate --remove-orphans # production docker-compose --env-file .deploy/.env.production up --build --force-recreate --remove-orphans ``` -------------------------------- ### Configure Django Settings for Quill (Python) Source: https://github.com/leehanyeong/django-quill-editor/blob/master/README.md Adds django_quill to INSTALLED_APPS in Django settings. Requires a Django project with settings.py. Input: existing INSTALLED_APPS list. Outputs updated settings for Quill integration. App must be in INSTALLED_APPS. ```python # settings.py INSTALLED_APPS = [ 'django.contrib.admin', ... 'django_quill', ] ``` -------------------------------- ### Add django_quill to INSTALLED_APPS Source: https://github.com/leehanyeong/django-quill-editor/blob/master/docs/index.rst Configuration step for Django projects to include the django_quill app. This allows Django to recognize and utilize the features provided by the package. ```python INSTALLED_APPS = [ 'django.contrib.admin', ... 'django_quill', ] ``` -------------------------------- ### Bulk Create Articles Source: https://context7.com/leehanyeong/django-quill-editor/llms.txt Creates multiple Article objects in a single database query for improved performance. Each article includes title and content with JSON-formatted data containing delta and HTML representations. Essential for importing or generating large amounts of content. ```python articles = Article.objects.bulk_create([ Article(title='Article 1', content='{"delta":"...","html":"Content 1
"}'), Article(title='Article 2', content='{"delta":"...","html":"Content 2
"}'), ]) ``` -------------------------------- ### Define Django Model with QuillField (Python) Source: https://github.com/leehanyeong/django-quill-editor/blob/master/README.md Creates a Django model using QuillField for rich text content. Requires django_quill in INSTALLED_APPS and model migrations. Input: model class definition. Outputs database-ready model with Quill editor. Run makemigrations and migrate after changes. ```python # models.py from django.db import models from django_quill.fields import QuillField class QuillPost(models.Model): content = QuillField() ``` -------------------------------- ### Django Template Usage for QuillField Source: https://context7.com/leehanyeong/django-quill-editor/llms.txt Demonstrates how to display QuillField content in Django templates, including rendering HTML content safely, displaying plain text excerpts, and integrating with forms. ```django {% load static %}Content
"}' # ) # Access through FieldQuill descriptor # content = article.content # Returns FieldQuill instance # print(type(content)) #Content
# print(content.delta) # {"ops":[{"insert":"Content\n"}]} # print(content.plain) # Content # print(content.json_string) # {"delta":"...","html":"..."} # Programmatic content update # new_content = '{"delta":"{\"ops\":[{\"insert\":\"Updated\\n\"}]}","html":"Updated
"}' # content.save(new_content, save=True) # Saves to database ``` -------------------------------- ### Querying and Filtering QuillField in Django ORM Source: https://context7.com/leehanyeong/django-quill-editor/llms.txt Explains how to query and filter data stored in QuillField using Django's ORM. It highlights limitations with direct JSON string searching and suggests using a separate plain text field for effective searching. ```python from django.db.models import Q from .models import Article # Basic queries work normally articles = Article.objects.all() article = Article.objects.get(pk=1) # QuillField stores JSON strings, so filtering is limited # Search in JSON string (database-dependent) articles = Article.objects.filter(content__icontains='hello') # Better approach: Use a separate plain text field for searching class Article(models.Model): title = models.CharField(max_length=200) content = QuillField() content_plain = models.TextField(blank=True) # For search def save(self, *args, **kwargs): # Auto-populate plain text field if self.content: try: self.content_plain = self.content.plain except: pass super().save(*args, **kwargs) ``` -------------------------------- ### DRF Integration for QuillField - Python Source: https://context7.com/leehanyeong/django-quill-editor/llms.txt Provides DRF serializer fields (QuillHtmlField, QuillPlainField) for exposing QuillField content as HTML or plain text in API responses. Supports default JSON output as well. ```python from rest_framework import serializers, viewsets from django_quill.drf.fields import QuillHtmlField, QuillPlainField # from .models import Article # Serializer with QuillHtmlField class ArticleSerializer(serializers.ModelSerializer): content = QuillHtmlField() # Returns HTML representation content_plain = QuillPlainField(source='content') # Returns plain text class Meta: model = Article fields = ['id', 'title', 'content', 'content_plain', 'created_at'] # ViewSet usage class ArticleViewSet(viewsets.ModelViewSet): queryset = Article.objects.all() serializer_class = ArticleSerializer # Alternative: Return full Quill JSON class ArticleFullSerializer(serializers.ModelSerializer): class Meta: model = Article fields = ['id', 'title', 'content'] # content field returns full JSON string by default ``` -------------------------------- ### Convert Existing Fields to QuillField - Django Management Command Source: https://context7.com/leehanyeong/django-quill-editor/llms.txt A Django management command to convert existing TextField or CharField data into the QuillField format, ensuring compatibility with the rich text editor. ```python # Command usage # python manage.py convert_to_quillStart editing here...
' ``` -------------------------------- ### Optimize Queries with Select Related Source: https://context7.com/leehanyeong/django-quill-editor/llms.txt Retrieves articles with related author data in a single database query using select_related. Uses only() to limit fetched fields to title and content for performance. Prevents N+1 query issues when accessing related objects. ```python articles = Article.objects.select_related('author').only('title', 'content') ``` -------------------------------- ### Create DRF Serializer with Quill Fields Source: https://github.com/leehanyeong/django-quill-editor/blob/master/docs/pages/rest-framework.md DRF serializer implementation using django-quill-editor's specialized fields. QuillHtmlField extracts HTML content from QuillField, while QuillPlainField provides plain text version. The source parameter maps the field to the original QuillField attribute. ```python from rest_framework import serializers from django_quill.drf.fields import QuillHtmlField, QuillPlainField from posts.models import QuillPost class QuillPostSerializer(serializers.ModelSerializer): content = QuillHtmlField() content_plain = QuillPlainField(source='content') class Meta: model = QuillPost fields = "__all__" ``` -------------------------------- ### Convert Text/Char Field to QuillField Data Source: https://github.com/leehanyeong/django-quill-editor/blob/master/docs/pages/migrating-to-quillfield.md This Django management command is used to transform existing data in a TextField or CharField to a format compatible with QuillField. It modifies the database directly, so use with caution. Ensure you have backups before execution. ```shell python manage.py convert_to_quill posts NonQuillPost content ``` -------------------------------- ### Registering QuillPost Model in Django Admin Source: https://github.com/leehanyeong/django-quill-editor/blob/master/docs/pages/using-in-admin.md Register the model using Django's admin decorator in admin.py to enable the Quill editor in the admin interface. This depends on the model being defined with QuillField and django_quill_editor in INSTALLED_APPS. It provides an admin form with the rich text editor; no custom inputs or outputs beyond standard admin CRUD. Ensure Quill is properly loaded in admin templates if issues arise. ```python from django.contrib import admin from .models import QuillPost @admin.register(QuillPost) class QuillPostAdmin(admin.ModelAdmin): pass ``` -------------------------------- ### Update Model Field to QuillField Source: https://github.com/leehanyeong/django-quill-editor/blob/master/docs/pages/migrating-to-quillfield.md This Python code snippet shows how to change a model field from a standard Django TextField to a QuillField. This is a necessary step after data conversion and before creating migrations. ```python from django_quill.fields import QuillField class NonQuillPost(models.Model): content = QuillField() ``` -------------------------------- ### Parse Quill JSON with Quill Class - Python Source: https://context7.com/leehanyeong/django-quill-editor/llms.txt The Quill class parses Quill JSON strings into Python objects, providing access to HTML, delta, and plain text representations. It handles potential parsing errors. ```python from django_quill.quill import Quill, QuillParseError # Parse Quill JSON string json_string = '{"delta":"{\"ops\":[{\"insert\":\"Hello\\n\"}]}","html":"Hello
"}' quill = Quill(json_string) print(quill.html) # Output:Hello
print(quill.delta) # Output: {"ops":[{"insert":"Hello\n"}]} print(quill.plain) # Output: Hello # Handle parsing errors try: invalid_quill = Quill('invalid json') except QuillParseError as e: print(f"Parse error: {e}") # Used internally by FieldQuill # article = Article.objects.first() # quill_obj = article.content.quill # Returns Quill instance ``` -------------------------------- ### Django QuillField: Model for Rich Text Source: https://context7.com/leehanyeong/django-quill-editor/llms.txt Defines a Django model field 'QuillField' to store rich text content. It saves data in JSON format containing both Quill's Delta and HTML representations. This field integrates automatically with Django forms and admin interfaces. Accessing the field provides HTML, Delta JSON, and plain text outputs. ```python from django.db import models from django_quill.fields import QuillField class Article(models.Model): title = models.CharField(max_length=200) content = QuillField() created_at = models.DateTimeField(auto_now_add=True) # Accessing field data article = Article.objects.first() print(article.content.html) # Get HTML representation print(article.content.delta) # Get Quill Delta JSON print(article.content.plain) # Get plain text (HTML stripped) # Creating new content article = Article.objects.create( title="My Article", content='{"delta":"{\"ops\":[{\"insert\":\"Hello World\\n\"}]}","html":"Hello World
"}' ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.