PageRenderTime 6ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/modeltests/ordering/models.py

https://code.google.com/p/mango-py/
Python | 26 lines | 8 code | 1 blank | 17 comment | 3 complexity | 7c1f7b214e0fa26b40c1753a5b2f5161 MD5 | raw file
 1"""
 26. Specifying ordering
 3
 4Specify default ordering for a model using the ``ordering`` attribute, which
 5should be a list or tuple of field names. This tells Django how to order
 6``QuerySet`` results.
 7
 8If a field name in ``ordering`` starts with a hyphen, that field will be
 9ordered in descending order. Otherwise, it'll be ordered in ascending order.
10The special-case field name ``"?"`` specifies random order.
11
12The ordering attribute is not required. If you leave it off, ordering will be
13undefined -- not random, just undefined.
14"""
15
16from django.db import models
17
18
19class Article(models.Model):
20    headline = models.CharField(max_length=100)
21    pub_date = models.DateTimeField()
22    class Meta:
23        ordering = ('-pub_date', 'headline')
24
25    def __unicode__(self):
26        return self.headline