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'] 
# 按订单降序排列,-表示降序

猜你喜欢

转载自blog.csdn.net/zhaoyangjian724/article/details/82011568
今日推荐