Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to perform Django admin background app operation in CMDB

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report