Chapter Xadmin Introduction

Source: Internet
Author: User
Tags json install django pip install django

Xadmin Document Author: 615chaoge 2017 August 15 15:52

Quick Start Xadmin

For using Xadmin, the Django 1.4 needs to is installed and an Admin Site have to be activated. installation

Using PIP:

Pip Install Django-xadmin

SOURCE Installation

Go to Https://github.com/sshwsfc/django-xadmin to download the latest source package or clone git library and execute it under the project directory:

Pip Install-r requirements.txt

Annotations

Before executing you can edit the file requirements.txt, where XLWT is not required, if you do not need to export the features of Excel, you can delete this run Demo

If you downloaded the Xadmin source package, you will find the Demo_app directory under the project directory and execute the command to quickly open a Xadmin demo instance:

CD Demo_app
python manage.py runserver

Open the browser and enter http://127.0.0.1:8000 to see the effect. use in your own project

Xadmin as a Django module, it's easy to use in Django's Web site.

First edit settings.py Add Xadmin module to Installed_apps (note that the APP required to install Django Admin is also installed, but django.admin can not be installed):

Installed_apps = (...

' Xadmin ',
' crispy_forms ',
' reversion ',

...
)

Then add url-patterns and Autodiscover actions:

Import Xadminxadmin.autodiscover () # version module autoenrollment requires version-controlled Modelfrom xadmin.plugins import Xversionxversion.registe_ Models () Urlpatterns = Patterns ("",
url (r ' xadmin/', include (Xadmin.site.urls)),)

To collect media files:


[Python] View plain copy

Python manage.py collectstatic



xadmin Plug- in Plugin Overview

built-in plugins

Action function

The action plugin provides the data selection function on the Data list page, and the selected data can be handled in a special action. The Action provided by default is the bulk delete feature. screenshot

Use

The developer can set the actions property of the Model Optionclass, which is a list of classes that contain the Action you want to enable. The system already has the default built-in action to delete the data, but you can create your own action to achieve a specific function, and the example of making an action is as follows.

The first step is to create an Action class that needs to inherit Baseactionview. Baseactionview is a subclass of Modeladminview:

From xadmin.plugins.actions import baseactionviewclass myaction (BaseActionView):      #  Here you need to fill in three properties     action_name =  "My_action"      #:  is equivalent to this  Action  's only mark,  try to use a more targeted name     description =  _ (U ' test selected % (verbose_name_plural) s ')  #:  description,  appears in the  Action  menu,

  can use   '% (verbose_name_plural) s '   instead of  Model  name.

    model_perm =  ' Change '     #:  the  Action  required permissions     #  then implement  do_action  method     def do_action (self,  queryset):         # queryset  is a   that contains the data that has been selected Queryset         for obj in queryset:              # obj  operation                       #  back to  httpresponse          Return httpresponse (...)

Then use this Action in the Model's Optionclass:

Class Mymodeladmin (object):

actions = [Myaction,]

This completes your own Action API .

Class Xadmin.plugins.actions.ActionPlugin (Admin_view) [source]


Data Filter function

Data filtering on the data list page, including: Blur Search, Digital range search, date search, etc. screenshot

Use

Set the following properties in Model Optionclass:

List_filter Properties:

This property specifies the name of the column that can be filtered, and the system automatically generates the Finder

Search_fields Properties:

property specifies the name of the data column that can be searched through the search box, and search box searches use a fuzzy Lookup method, typically used to search for string fields such as the first name

Free_query_filter Properties:

The default is True to specify whether you can search freely. If you turn on your own search, users can use URL parameters for specific searches, such as:

Http://xxx.com/xadmin/auth/user/?name__contains=tony

Examples of using filters:

Class Useradmin (object):
list_filter = (' Is_staff ', ' is_superuser ', ' is_active ')
search_fields = (' Usernam E ', ' first_name ', ' last_name ', ' email ')
version

No filter is currently in production

You can also make your own filters for specific filters. The filter needs to inherit the Xadmin.filters.BaseFilter class and register the filter with Xadmin.filters.manager.

Chart Plugin function

On the Data list page, generate a chart with the list data. You can specify multiple data columns to generate multiple charts. screenshot

Use

Set the Data_charts property in Model Optionclass, which is the dict type, key is the name of the chart, and value is the specific setting property of the chart. Examples of Use:

Class Recordadmin (object):
data_charts = {
"User_count": {' title ': U "user Report", "X-field": "Date",  "Y-field": ("User_count", "View_count"), "Order": (' Date ',)},
"Avg_count": {' title ': U "avg Report", "X-field": "Date", "Y-field": (' Avg_count ',), "Order": (' Date ',)}
}

The main properties of the chart are:

Title: The display name of the chart

X-field: Chart X-axis data column, usually date, time, etc.

Y-field: The Y-axis data column of a chart, which is a list that can set multiple columns at the same time so that data from multiple columns is displayed in the same chart

Order: Sort information, use sorted version of data list if not written

No API

Class Xadmin.plugins.chart.ChartsPlugin (Admin_view) [source]


Class Xadmin.plugins.chart.ChartsView (Request, *args, **kwargs) [source]


Bookmark function

Record Data list page specific data filtering, sorting and other results. Added bookmarks can also be added as widgets in the home dashboard

Use

Set the following properties in the Model Optionclass:

Show_bookmarks Properties:

Set whether the bookmark feature is turned on by default to True

List_bookmarks Properties:

Sets the default bookmark. Users can add their own bookmarks on the list page, you can also implement some bookmarks, using the following example:

Class Useradmin (object): List_bookmarks = [{' title ': ' Female ', # bookmark name, display ' query ' in the Bookmarks menu: {' G Ender ': True}, # Filter parameter, is the standard Queryset filter ' order ': ('-age '), # sort parameter ' cols ': (' first_name ', ' age ', ' p
    Hones '), # Displays the column ' Search ': ' Tom ' # Searching for parameters, specifying what to search for}, {...} ]
version

Not currently

Data Export function

The plugin provides data export functionality in the Data list page, which can be exported in Excel, CSV, XML, and JSON format. screenshot

Use

Annotations

If you want to export Excel data, you need to install XLWT.

By default, Xadmin provides data export in Excel, CSV, XML, and JSON in four formats. You can disable the data export feature by setting the List_export property of Optionclass to specify which export formats to use (each of the four uses XLS, CSV, XML, JSON), or set List_export to None. Examples are as follows:

Class Mymodeladmin (object):

List_export = (' xls ', xml ', ' JSON ')

List timed Refresh function

The plugin provides a timed refresh feature on the Data list page, which is useful for situations where it is necessary to refresh the list page in real-time to view the instant data. screenshot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.