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'] 
    # 按订单降序排列,-表示降序
  • 相关阅读:
    试试 cocos creator 3.0 还算可以
    安卓按键辅助(类似按键精灵)
    一次github遭遇
    NSString
    Navicat for SQL Server V10.0.10
    申请博客第一天
    Google Earth的脫機應用-本地模擬瓦片系統
    Vs2010+opencv2.3.1 imread出现异常
    tcpdump工具注意事项
    选择服务器托管机房的注意事项
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349104.html
Copyright © 2011-2022 走看看