In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
CMDB to achieve data display function part of the code. Views.pydef asset (request): asset = Asset.objects.all () return render_to_response ("asset.html", {'asset': asset}) models.pyclass Asset (models.Model): ipaddr = models.CharField (max_length=20, verbose_name=u'IP address', primary_key=True) # primary_key needs to be defined, otherwise the id column hostname = models.CharField (max_length=30, verbose_name=u' hostname') nodes = models.CharField (max_length=20) will be automatically created Verbose_name=u' application node') applications = models.CharField (max_length=30, verbose_name=u' application name') group = models.CharField (max_length=20, verbose_name=u' application group name') memory = models.CharField (max_length=5, verbose_name=' memory size') env = models.CharField (max_length=5 Verbose_name=' environment variable') flag = models.PositiveSmallIntegerField (verbose_name=u'flag') # def _ _ unicode__ (self): # return upright% s _ unicode__ (self): # return upright% s _ self.app% s'% (self.ipaddr, self.hostname, self.nodes, self.app, self.group, self.memory, self.disk, self.cpu) class Meta: db_table = 'fcenv_copy' # Table name The default is app name + class name verbose_name = u 'host asset information' verbose_name_plural = u 'host asset information management' asset.html IP address machine name node application name group memory Environment variable flag operation {% for value in asset%} {{value.hostname}} {{value.nodes}} {{value.applications}} {{value.group}} {{value.memory}} {{value.env}} {{value.flag}} Edit connection deletion {% endfor%}
The following are common ORM operations:
# models.Tb1.objects.create adds a piece of data to accept dictionary type data * * kwargs
# obj = models.Tb1 (C1 models.Tb1.objects.get xxoo') # obj.save () # check # # models.Tb1.objects.get (id=123) # to get a single piece of data Error report (not recommended) # models.Tb1.objects.all () # get all # models.Tb1.objects.filter (name='seven') # get data for specified condition # delete # # models.Tb1.objects.filter (name='seven'). Delete () # Delete data for specified condition # change to # models.Tb1.objects.filter (name='seven') .update (gender='0') # update the data of the specified condition All support * * kwargs # obj = models.Tb1.objects.get (id=1) # modify a single data # obj.c1 = '111' # obj.save () # get the number # # models.Tb1.objects.filter (name='seven'). Count () # is greater than Less than # # models.Tb1.objects.filter (id__gt=1) # get values with id greater than 1 # models.Tb1.objects.filter (id__lt=10) # get values with id less than 10 # models.Tb1.objects.filter (id__lt=10, id__gt=1) # get values with id greater than 1 and less than 10 # in # # models.Tb1.objects.filter (id__in= [11,22) 33]) # get data with id equal to 11,22,33 # models.Tb1.objects.exclude (id__in= [11,22,33]) # not in # contains # # models.Tb1.objects.filter (name__contains= "ven") # models.Tb1.objects.filter (name__icontains= "ven") # icontains case insensitive # models.Tb1.objects.exclude (name__icontains= "ven") # range # # models.Tb1.objects.filter (id__range= [1) 2]) # range bettwen and # other similar # # startswith Istartswith, endswith, iendswith, # order by # # models.Tb1.objects.filter (name='seven'). Order_by ('id') # asc # models.Tb1.objects.filter (name='seven'). Order_by ('-id') # desc # limit, offset # # models.Tb1.objects.all () [10:20] # group by from django.db.models import Count, Min, Max, Sum # models.Tb1.objects.filter ('id') .values (' id') .annotate (c=Count ('num'))
# SELECT "app01_tb1". "id", COUNT ("app01_tb1". "num") AS "c" FROM "app01_tb1" WHERE "app01_tb1". "C1" = 1 GROUP BY "app01_tb1". "id"
Many-to-one relationships multi-table association query.
From django.db import modelsclass Reporter (models.Model): first_name = models.CharField (max_length=30) last_name = models.CharField (max_length=30) email = models.EmailField () def _ str__ (self): # _ unicode__ on Python 2 return "% s% s"% (self.first_name Self.last_name) class Article (models.Model): headline = models.CharField (max_length=100) pub_date = models.DateField () reporter = models.ForeignKey (Reporter, on_delete=models.CASCADE) def _ _ str__ (self): # _ unicode__ on Python 2 return self.headline class Meta: ordering = ('headline' ) > r.article_set.filter (headline__startswith='This') # Find all Articles for any Reporter whose first name is "John". > > Article.objects.filter (reporter__first_name='John')
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.