zoukankan      html  css  js  c++  java
  • python django Meta(元)的选择 排序

    class julia(models.Model):
        horn_length = models.CharField(max_length=200)
        class Meta:
            ordering = ["horn_length"]
            verbose_name_plural = "oxen"
        def __str__(self):              # __unicode__ on Python 2
            return self.horn_length
    
    
    	
    node2:/exam/mysite# python manage.py makemigrations
    Migrations for 'polls':
      polls/migrations/0008_auto_20180805_2023.py
        - Create model julia
        - Delete model Ox
    node2:/exam/mysite# python manage.py migrate
    Operations to perform:
      Apply all migrations: admin, auth, contenttypes, polls, sessions
    Running migrations:
      Applying polls.0008_auto_20180805_2023... OK
    node2:/exam/mysite#
    
    
    node2:/exam/mysite#python
    Python 2.7.3 (default, Mar 30 2017, 20:15:12) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>  import os,django
      File "<stdin>", line 1
        import os,django
        ^
    IndentationError: unexpected indent
    >>> import os,django
    >>> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    'mysite.settings'
    >>> django.setup()
    >>> from polls.models import *
    >>> julia.objects.all():
      File "<stdin>", line 1
        julia.objects.all():
                           ^
    SyntaxError: invalid syntax
    >>> julia.objects.all()
    <QuerySet [<julia: 11111>, <julia: 22222>, <julia: 33333>]>
    >>> 
    
    
    ordering=['order_date'] 
    # 按订单升序排列
    ordering=['-order_date'] 
    # 按订单降序排列,-表示降序
  • 相关阅读:
    ubuntu 10.04安装增强功能 共享文件夹
    CRF简介入门
    Ant 的build.xml 详解
    eclipse中各种颜色和背景的设置
    第13章 类继承 --抽象基类
    第13章 类继承
    团队开发之绩效考核二
    站立会议
    团队站立会议
    团队开发站立会议
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349104.html
Copyright © 2011-2022 走看看