Skip to main content

Intelligent management for multiple subclass models in django's admin site.

Project description

pip install django-msms-admin

Intelligent management for multiple subclass models in django's admin site.

Install

pip install django-msms-admin

Installed Classes

  • DjangoMsmsModelAbstractBase

    The base model must inherit from DjangoMsmsModelAbstractBase class. It provides app_label, model_name, type_name fields and auto save the values.

  • DjangoMsmsAdmin

    The base model admin must inherit from DjangoMsmsAdmin class.

  • DjangoSubclassAdmin

    All subclass models' admin must inherit from DjangoSubclassAdmin class.

Configurations

  • DjangoMsmsAdmin.subclasses

    The config item is used to provide choices in select_subclass_model_view. If NOT provide, the system will auto find all registered subclasses. The structure of subclasses is a three-level-tree. e.g.

    subclasses = [{
        "title": "category1",
        "children": [{
            "title": "category11",
            "children: [
                Model1,
                Model2,
                Model3,
            ]
        },{
            "title": "category12",
            "children": [
                Model4,
                Model5,
                Model6,
            ]
        }]
    },{
        "title": "category2",
        "children": [{
            "title": "category21",
            "children": [
                Model7,
                Model8,
            ]
        },{
            "title": "category22,
            "children": [
                Model9,
            ]
        }]
    }]
    
  • DjangoMsmsModelAbstractBase.cascade_select_description

  • DjangoMsmsModelAbstractBase.cascade_select_image

    Config item cascade_select_description and cascade_select_image are use to display more information while you selected a subclass. cascade_select_image is url string of an image.

Usage

pro/settings.py

INSTALLED_APPS = [
    ...
    'django_simple_tags',
    'django_static_jquery3',
    'django_msms_admin',
    ...
]

app/model.py

from django.db import models
from django.contrib.staticfiles.templatetags.staticfiles import static
from django_msms_admin.models import DjangoMsmsModelAbstractBase

class Book(DjangoMsmsModelAbstractBase, models.Model):
    title = models.CharField(max_length=64)
    author = models.CharField(max_length=64)

    def __str__(self):
        return self.title

class ComputerBook(Book):
    serial = models.CharField(max_length=64)

    cascade_select_description = "These books are all about computers."
    cascade_select_image = static("app/img/computer-book.jpg")

class NovelBook(Book):
    country = models.CharField(max_length=64)

app/admin.py

from django.contrib import admin
from django_msms_admin.admin import DjangoMsmsAdmin
from django_msms_admin.admin import DjangoSubclassAdmin

from .models import Book
from .models import ComputerBook
from .models import NovelBook

class BookAdmin(DjangoMsmsAdmin, admin.ModelAdmin):

    list_display = ["title", "author", "type_name"]
    list_filter = ["type_name"]


admin.site.register(Book, BookAdmin)
admin.site.register(ComputerBook, DjangoSubclassAdmin)
admin.site.register(NovelBook, DjangoSubclassAdmin)

Release

v0.2.0 2020/03/07

  • Use model's msms_category, msm_priority property to do model category and sorting.
  • Rename cascade_select_description to msms_description.
  • Rename cascade_select_preview_image to msms_image.

v0.1.2 2020/03/06

  • Fix keywords in setup.py and read requirements.txt for install_requires.

v0.1.1 2020/03/05

  • Add DjangoMsmsModelAbstractBase.get_real_object method.

v0.1.0 2020/03/03

  • First release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-msms-admin-0.2.0.tar.gz (9.6 kB view details)

Uploaded Source

File details

Details for the file django-msms-admin-0.2.0.tar.gz.

File metadata

  • Download URL: django-msms-admin-0.2.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

File hashes

Hashes for django-msms-admin-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4a2f40be02db5efcbf879ac88e56c9153f903fbcfe23bcfaf2733d87848fdc8f
MD5 d48ef11dda741cdf93168357af4cdddc
BLAKE2b-256 30674df2cd21b16aed61ab090a20331afb4d6c70622fa76503cd3e88e968bb46

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page