mirror of
https://github.com/django/django.git
synced 2024-12-28 20:16:19 +00:00
e973ee6a98
The option can be used to force pre 1.6 style SELECT on save behaviour. This is needed in case the database returns zero updated rows even if there is a matching row in the DB. One such case is PostgreSQL update trigger that returns NULL. Reviewed by Tim Graham. Refs #16649
34 lines
835 B
Python
34 lines
835 B
Python
# coding: utf-8
|
|
"""
|
|
1. Bare-bones model
|
|
|
|
This is a basic model with only two non-primary-key fields.
|
|
"""
|
|
from django.db import models
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class Article(models.Model):
|
|
headline = models.CharField(max_length=100, default='Default headline')
|
|
pub_date = models.DateTimeField()
|
|
|
|
class Meta:
|
|
ordering = ('pub_date','headline')
|
|
|
|
def __str__(self):
|
|
return self.headline
|
|
|
|
class ArticleSelectOnSave(Article):
|
|
class Meta:
|
|
proxy = True
|
|
select_on_save = True
|
|
|
|
@python_2_unicode_compatible
|
|
class SelfRef(models.Model):
|
|
selfref = models.ForeignKey('self', null=True, blank=True,
|
|
related_name='+')
|
|
|
|
def __str__(self):
|
|
return SelfRef.objects.get(selfref=self).pk
|