PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/modeltests/ordering/models.py

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