2014-05-15 19:41:55 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-05-02 03:31:56 +02:00
|
|
|
"""
|
2014-09-24 07:13:13 +02:00
|
|
|
Bare-bones model
|
2006-05-02 03:31:56 +02:00
|
|
|
|
|
|
|
This is a basic model with only two non-primary-key fields.
|
|
|
|
"""
|
2011-07-13 11:35:51 +02:00
|
|
|
from django.db import models
|
2012-08-12 12:32:08 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2006-05-02 03:31:56 +02:00
|
|
|
|
2011-10-13 20:04:12 +02:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
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, default='Default headline')
|
2006-05-02 03:31:56 +02:00
|
|
|
pub_date = models.DateTimeField()
|
2006-06-04 02:23:51 +02:00
|
|
|
|
2006-12-19 04:38:38 +01:00
|
|
|
class Meta:
|
2013-10-26 21:15:03 +02:00
|
|
|
ordering = ('pub_date', 'headline')
|
2007-02-14 07:32:32 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2006-05-02 03:31:56 +02:00
|
|
|
return self.headline
|
2013-05-20 17:45:24 +02:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-08-30 08:41:07 +02:00
|
|
|
class ArticleSelectOnSave(Article):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
select_on_save = True
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2013-05-20 17:45:24 +02:00
|
|
|
@python_2_unicode_compatible
|
|
|
|
class SelfRef(models.Model):
|
2015-07-22 16:43:21 +02:00
|
|
|
selfref = models.ForeignKey(
|
|
|
|
'self',
|
|
|
|
models.SET_NULL,
|
|
|
|
null=True, blank=True,
|
|
|
|
related_name='+',
|
|
|
|
)
|
2015-11-20 16:31:33 +01:00
|
|
|
article = models.ForeignKey(Article, models.SET_NULL, null=True, blank=True)
|
2013-05-20 17:45:24 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
2014-11-20 22:25:49 +01:00
|
|
|
# This method intentionally doesn't work for all cases - part
|
|
|
|
# of the test for ticket #20278
|
2013-05-20 17:45:24 +02:00
|
|
|
return SelfRef.objects.get(selfref=self).pk
|