Giter Site home page Giter Site logo

adityatelange / django-trix-fork Goto Github PK

View Code? Open in Web Editor NEW

This project forked from islco/django-trix

6.0 2.0 1.0 281 KB

Home Page: https://pypi.org/project/django-trix-fork/

License: MIT License

Python 30.24% JavaScript 7.88% CSS 60.87% HTML 1.01%

django-trix-fork's Introduction

django-trix-fork

Trix rich text editor widget for Django, using Trix 1.2.3.

Installation

  1. From PyPI:

    pip install django-trix-fork

  2. Install trix as app in django Add to INSTALLED_APPS:

    INSTALLED_APPS = (
        ...
        'trix',
        ...
    )
    
  3. Add route to urls.py:

    urlpatterns = [
        ...
        url(r'^trix/', include('trix.urls')),
        ...
    ]
    
  4. Add django-trix variables to your app/settings.py:

    ...
    # valid file extentions for attachment 
    TRIX_EXTENSIONS = ['.jpg', '.png'] 
    
    # folder where attachments will be saved
    TRIX_URI = 'trix' 
    ...
    
  5. Set-Up trix-django tables:

    python manage.py makemigrations trix
    python manage.py migrate

Done

How to use django-trix

django-trix includes a form widget, a model field, and a model admin mixin that enables the rich text editor. You can use any of these methods, but you do not need to use all.

Model

To enable the editor in the Django admin (or any form) via the model field, use the Trix model field TrixField which inherits from django.db.models.TextField:

from django.db import models
from trix.fields import TrixField

class Post(models.Model):
    content = TrixField('Content')

Admin

To enable the editor in the Django admin, inherit from TrixAdmin and set the trix_fields attribute to a list of the fields that use an editor:

from myawesomeblogapp.models import Post
from trix.admin import TrixAdmin

@admin.register(Post)
class PostAdmin(TrixAdmin, admin.ModelAdmin):
    trix_fields = ('content',)

Forms and Templates

The editor can be used in forms and templates by adding the TrixEditor widget to a form field:

from django import forms
from trix.widgets import TrixEditor

class EditorForm(forms.Form):
    content = forms.CharField(widget=TrixEditor)

In the template, just use the form as you normally would, but be sure to include the associated media:

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Trix Editor Test</title>
        {{ form.media.css }}
    </head>
    <body>
        <form>
            {{ form }}
        </form>
        {{ form.media.js }}
    </body>
</html>

CSS in head, JS at end of body, because you are a responsible developer.

What Works

Basically Everything :) from Rich Text formatting to Uploading Attachments !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.