Get the App
SLTechnology News&Howtos  ›  Development  › 

How to perform Django admin background app operation in CMDB

Shulou Source: shulou.com Published: 2022-06-02 10:24:52 09月30日 Update

How to carry out the Django admin background app operation in CMDB? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

The background function of Django is very useful:

First, you need to register app to the background.

Cat asset/apps.pyfrom _ _ future__ import unicode_literalsfrom django.apps import AppConfigclass AssetConfig (AppConfig): name = 'asset' verbose_name =' Environment list'# the name cat asset/admin.pyfrom django.contrib import adminfrom asset.models import Asset_pro, Asset_test, Redis_pro# Register your models here.admin.site.register ([Asset_pro, Asset_test, Redis_pro]) displayed in the background

After logging in the background, I found that the operating object was wrong: get () returned more than one topic-- it returned 2!

The reason is that multiple pieces of the same data are inserted into the database, so that when querying, it is impossible to distinguish which piece of data needs to be obtained.

So you need to define it in models:

Class Asset_test (models.Model): nodes = models.CharField (max_length=20, verbose_name=u' application node') applications = models.CharField (max_length=30, verbose_name=u' application name', primary_key=True) # background app default change object ipaddr = models.CharField (max_length=20, verbose_name=u'IP address') # primary_key needs to be defined, otherwise the id column mobile = models.CharField (max_length=20) will be created automatically Verbose_name='mobile') DMS = models.CharField (max_length=5, verbose_name='DMS') flag = models.CharField (max_length=5, verbose_name='flag') def _ _ unicode__ (self): return u "% s"% (self.ipaddr) class Meta: db_table = 'fcenv_test' # Table name The default is app name + class name verbose_name = u 'test environment service information' verbose_name_plural = u 'test environment asset management'

The principle is that there must be a column of data that is primary_key, and then the data will be manipulated normally.

The data is modified in the background, and the front end is displayed in real time.

This is the answer to the question about how to operate Django admin backend app in CMDB. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Tags: Background data environment questions objects more help application test answer practical easy easy information content front end function principle reason name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Redmi vpn Microsoft Shulou Information