2006-05-02 03:31:56 +02:00
|
|
|
from django.db import models
|
|
|
|
|
2011-10-13 20:04:12 +02:00
|
|
|
|
2006-05-02 03:31:56 +02:00
|
|
|
class Article(models.Model):
|
2007-08-05 07:14:46 +02:00
|
|
|
headline = models.CharField(max_length=100)
|
2006-05-02 03:31:56 +02:00
|
|
|
pub_date = models.DateField()
|
|
|
|
expire_date = models.DateField()
|
2013-01-20 07:53:45 +01:00
|
|
|
|
2006-05-02 03:31:56 +02:00
|
|
|
class Meta:
|
|
|
|
get_latest_by = "pub_date"
|
|
|
|
|
2013-01-12 09:37:19 +01:00
|
|
|
|
2006-05-02 03:31:56 +02:00
|
|
|
class Person(models.Model):
|
2007-08-05 07:14:46 +02:00
|
|
|
name = models.CharField(max_length=30)
|
2006-05-02 03:31:56 +02:00
|
|
|
birthday = models.DateField()
|
|
|
|
# Note that this model doesn't have "get_latest_by" set.
|
2014-10-08 17:27:17 +02:00
|
|
|
|
|
|
|
|
2022-06-13 03:08:21 +02:00
|
|
|
class Comment(models.Model):
|
|
|
|
article = models.ForeignKey(Article, on_delete=models.CASCADE)
|
|
|
|
likes_count = models.PositiveIntegerField()
|
|
|
|
|
|
|
|
|
2014-10-08 17:27:17 +02:00
|
|
|
# Ticket #23555 - model with an intentionally broken QuerySet.__iter__ method.
|
|
|
|
|
2022-02-03 20:24:19 +01:00
|
|
|
|
2014-10-08 17:27:17 +02:00
|
|
|
class IndexErrorQuerySet(models.QuerySet):
|
|
|
|
"""
|
|
|
|
Emulates the case when some internal code raises an unexpected
|
|
|
|
IndexError.
|
|
|
|
"""
|
2022-02-03 20:24:19 +01:00
|
|
|
|
2014-10-08 17:27:17 +02:00
|
|
|
def __iter__(self):
|
|
|
|
raise IndexError
|
|
|
|
|
|
|
|
|
|
|
|
class IndexErrorArticle(Article):
|
|
|
|
objects = IndexErrorQuerySet.as_manager()
|