✍🏻 Edit contents directly on your page with Django
pip install djsuperadmin
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 %}
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 !
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>
Try out the new djsuperadmin in_place mode for raw content! Type in your settings.py:
DJSUPERADMIN = {"INPLACE_EDIT": True}