Skip to content

lotrekagency/djsuperadmin

 
 

Repository files navigation

DjSuperAdmin PyPI Codecov GitHub Workflow Status GitHub

✍🏻 Edit contents directly on your page with Django

Here how it works!

DjSuperAdmin demo

Installation

pip install djsuperadmin

Setup

Add djsuperadmin to your INSTALLED_APPS in settings.py

INSTALLED_APPS = [
    # ...
    'djsuperadmin'
]

And import all the required js files in the footer

{% load djsuperadmintag %}

{% djsuperadminjs %}

Usage:

Simple:

Djsuperadmin now comes with its own content model. You can use it directly in templates, like this:

{% load djsuperadmintag %}

...

<body>
    <p>
        {% superadmin_content 'Some default content' %}
    </p>
</body>

Try also the raw content {% superadmin_content_raw 'Some default content' %} to edit things without a wysiwyg !

Advanced:

Define your custom Content model using DjSuperAdminMixin and provide an endpoint to GET/PATCH your content

from django.db import models
from djsuperadmin.mixins import DjSuperAdminMixin


class GenericContent(models.Model, DjSuperAdminMixin):

    identifier = models.CharField(max_length=200, unique=True)
    content = models.TextField()

    @property
    def superadmin_get_url(self):
        return f'/api/content/{self.pk}'

    @property
    def superadmin_patch_url(self):
        return f'/api/content/{self.pk}'

Then in your template

{% load djsuperadmintag %}

...

<body>
    <p>
        {% superadmin_content your_object 'your_object_attribute' %}
    </p>
</body>

Settings:

Try out the new djsuperadmin in_place mode for raw content! Type in your settings.py:

DJSUPERADMIN = {"INPLACE_EDIT": True}

About

✍🏻 Edit contents directly on your page with Django

Resources

License

Stars

Watchers

Forks

Languages

  • Python 48.9%
  • JavaScript 39.8%
  • SCSS 10.3%
  • Makefile 1.0%