Python论坛  - 讨论区

标题:[python-chinese] django中ordering设置怎么没有效果?

2006年04月27日 星期四 22:15

HoLin holin.he at gmail.com
Thu Apr 27 22:15:55 HKT 2006

#---------我的 models file-------------------
#coding=utf-8
from django.db import models

# Create your models here.
class Note(models.Model):
        items   = models.CharField('条目', maxlength=400)
        money   = models.FloatField('价格', max_digits=5, decimal_places=2)
        tagIds  = models.CharField('标签',maxlength=40)
        memo    = models.TextField('说明', blank=True)
        addtime = models.DateTimeField('时间')
        def __repr__(self):
                return self.items
        class Admin: pass
        class META:
                ordering = ['-addtime']

class Tag(models.Model):
        title   = models.CharField('名称', maxlength=50)
        count   = models.IntegerField("使用数")

        class Admin: pass

        def __repr__(self):
                return self.title

#---the urls file ------------------
from django.conf.urls.defaults import *
from finacing.note.models import *

info_dict = {
    'queryset': Note.objects.all(),

}


urlpatterns = patterns('',
        (r'^/*$',
'django.views.generic.list_detail.object_list',dict(paginate_by=2,
**info_dict)),
        (r'^site_media/(?P.*)$', 'django.views.static.serve',
{'document_root': 'F:\\djangoPrj\\finacing\\media'}),
    # Example:
    # (r'^finacing/', include('finacing.apps.foo.urls.foo')),

    # Uncomment this for admin:
     (r'^add/$', 'finacing.note.views.add'),
     (r'^addtag/$', 'finacing.note.views.addtag'),
         (r'^admin/', include('django.contrib.admin.urls')),
)

我改变ordering如下,但是列表排序没有变化,还是按数据库里的顺序:
class META:
                ordering = ['addtime']

有谁用过ordering的帮我看看阿。
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060427/90712205/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号