Py学习  »  Django

如何根据数据表里面的datetime字段进行排序?

加个小括号_ • 7 年前 • 1887 次点击  
class CommissionRecord(models.Model):
    user = models.ForeignKey(User)
    no = models.CharField(max_length=100)
    add_time = models.DateTimeField(auto_now_add=True)
    desc = models.CharField(max_length=100)
    amount = models.IntegerField()
    bid = models.ForeignKey(Bid)

如何根据该表取出今天的记录,本周的记录,本月的记录,踩了好多坑啊,感觉都不行,datetime.date.today()也不行。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/3064
 
1887 次点击  
文章 [ 4 ]  |  最新文章 7 年前
加个小括号_
Reply   •   1 楼
加个小括号_    7 年前

@静守彷徨 我是要取出这表里面属于今天的数据,本周的数据和本月的数据。谢谢了哈

静守彷徨
Reply   •   2 楼
静守彷徨    7 年前
def index(req):
    t1 = Article.objects.all().order_by('date_time')
    return render(req,'index.html',{'date_time':t1})
静守彷徨
Reply   •   3 楼
静守彷徨    7 年前

def index(req): t1 = Article.objects.all().order_by('date_time') return render(req,'index.html',{'date_time':t1})

静守彷徨
Reply   •   4 楼
静守彷徨    7 年前

def index(req): t1 = Article.objects.all().order_by('date_time') return render(req,'index.html',{'date_time':t1})