🚀 Getting started
This page takes you from installation to your first model in the admin. The
examples use a blog project: the project package mysite and an app called
blog.
Install the package
pip install django-content-studio
Configure Django
-
Add Content Studio and Django REST Framework to
INSTALLED_APPS. Keepdjango.contrib.admininstalled: Content Studio records its activity log with it. The order of the apps does not matter.# mysite/settings.pyINSTALLED_APPS = ["django.contrib.admin","django.contrib.auth","django.contrib.contenttypes","django.contrib.sessions","django.contrib.messages","django.contrib.staticfiles","rest_framework","content_studio","blog",] -
Mount the admin at a URL prefix.
admin/is the usual choice; the admin needs no other URL configuration.# mysite/urls.pyfrom django.urls import include, pathurlpatterns = [path("admin/", include("content_studio.urls")),]
Initialize Content Studio
The init_content_studio command sets up the site and the settings:
python manage.py init_content_studio
It asks which models to use for the media library (an item and a folder model, none by default), whether to use a tenant model, and which login backend to enable. Choose with the arrow keys; Esc asks to cancel. The command then:
- creates
studio.pynext to your settings, with the site (aContentStudioSiteinstance calledadmin_site) and its customization hooks as comments; - adds a
CONTENT_STUDIOblock to your settings withADMIN_SITEpointing at the new site. If the block already exists, the command reports it and leaves your settings as they are.
To run the command without prompts, pass every choice as a flag:
--media-item, --media-folder and --tenant (each as
app_label.Model), --login-backend, and --no-input for the defaults of
everything else. Run manage.py check afterwards: the
system checks report any problem with the
configuration.
Register a model
Take a plain Django model:
# blog/models.py
from django.db import models
class Article(models.Model):
class Status(models.TextChoices):
DRAFT = "draft", "Draft"
PUBLISHED = "published", "Published"
title = models.CharField(max_length=200)
body = models.TextField(blank=True)
status = models.CharField(
max_length=20, choices=Status.choices, default=Status.DRAFT
)
def __str__(self):
return self.title
Register it with a studio in the app's admin.py, where Content Studio
looks for registrations:
# blog/admin.py
from content_studio import register
from content_studio.admin import ModelStudio
from .models import Article
@register(Article)
class ArticleStudio(ModelStudio):
table_display = ["title", "status"]
list_filter = ["status"]
search_fields = ["title"]
Log in
Start the development server and open /admin/. Log in with the username
and password of a staff user, as in the classic Django admin. Articles
appear in the menu, with a list page you can search and filter, and an edit
page built from the model's fields.
Next steps
- Registering models: every studio option, singletons and inlines.
- Access control: model and object permissions.
- Widgets and form sets: field editors and edit page layouts.
- Settings: every
CONTENT_STUDIOsetting.