The Basics
Learn how to define, register, and customize Djing resources.
Defining Resources
By default, Djing resources are stored in the djing_admin/app/Djing directory of your application. You may generate a new resource using the djing:resource
command:
commander djing:resource Post --model="posts.models.Post"
This comand will generate a simple resource class below:
from djing.core.Fields.ID import ID
from djing.core.Http.Requests.DjingRequest import DjingRequest
from djing_admin.app.Djing.Resource import Resource as DjingResource
class Post(DjingResource):
model = 'posts.models.Post'
title = "id"
search = [
"id",
]
def fields(self, request: DjingRequest):
return [
ID.make("ID").sortable(),
]
def cards(self, request: DjingRequest):
return []
def filters(self, request: DjingRequest):
return []
def lenses(self, request: DjingRequest):
return []
def actions(self, request: DjingRequest):
return []
Registering Resources
By default, all resources within the djing_admin/app/Djing directory will automatically be registered with Djing.
As mentioned above, you are not required to manually register your resources; however, if you choose to do so, you may do so by overriding the resources
method of your DjingServiceProvider.
from djing_admin.app.Djing.User import User
from djing_admin.app.Djing.Post import Post
# ...
def resources(self):
Djing.resources_in('djing_admin/app/Djing')
Djing.resources_in([
User,
Post
])
Grouping Resources
If you would like to separate resources into different sidebar groups, you may override the group
property of your resource class:
from djing_admin.app.Djing.Resource import Resource as DjingResource
# ...
class Post(DjingResource):
group = "Posts"
Pagination
Djing has the ability to show pagination links for your Resource listings. You can choose between three different styles: “simple”, “load-more”, and “links”, depending on your application’s needs:
By default, Djing Resources are displayed using the “simple” style. However, you may customize this to use either the load-more
or links
styles by changing the value of the pagination
configuration option within your application’s djing_admin/config/djing.py
configuration file:
#
# You can choose between simple, load-more and links.
#
"pagination": os.getenv("DJING_PAGINATION", "simple")
Last updated