| 1 | """ |
| 2 | #. Save only modified fields on update |
| 3 | """ |
| 4 | from django.db import models |
| 5 | |
| 6 | class Article(models.Model): |
| 7 | headline = models.CharField(maxlength=100, default='Default headline') |
| 8 | body = models.TextField() |
| 9 | pub_date = models.DateTimeField() |
| 10 | |
| 11 | class Meta: |
| 12 | ordering = ('pub_date','headline') |
| 13 | |
| 14 | def __str__(self): |
| 15 | return self.headline |
| 16 | |
| 17 | __test__ = {'API_TESTS':""" |
| 18 | # Create a couple of Articles. |
| 19 | >>> from datetime import datetime |
| 20 | >>> a = Article(headline='Article 1', body='Body 1', pub_date=datetime(2007, 5, 5)) |
| 21 | >>> a.save() |
| 22 | |
| 23 | # Change headline and body on different instances, then save both to verify |
| 24 | # that each only updated the modified field. |
| 25 | >>> a1 = Article.objects.get(pk=a.id) |
| 26 | >>> a2 = Article.objects.get(pk=a.id) |
| 27 | >>> a1.headline = 'Changed article 1' |
| 28 | >>> a2.body = 'Changed body 1' |
| 29 | >>> a1.save() |
| 30 | >>> a2.save() |
| 31 | >>> a3 = Article.objects.get(pk=a.id) |
| 32 | >>> a3.headline |
| 33 | u'Changed article 1' |
| 34 | >>> a3.body |
| 35 | u'Changed body 1' |
| 36 | |
| 37 | # Fields entered at istantiation of a model which will already exists should be |
| 38 | # saved as well. |
| 39 | >>> a = Article(id=a.id, headline='Reset article 1', body='Reset body 1', pub_date=datetime(2007, 5, 5)) |
| 40 | >>> a.save() |
| 41 | >>> a3 = Article.objects.get(pk=a.id) |
| 42 | >>> a3.headline |
| 43 | u'Reset article 1' |
| 44 | >>> a3.body |
| 45 | u'Reset body 1' |
| 46 | """} |
| 47 | """ |
| 48 | #. Save only modified fields on update |
| 49 | """ |
| 50 | from django.db import models |
| 51 | |
| 52 | class Article(models.Model): |
| 53 | headline = models.CharField(maxlength=100, default='Default headline') |
| 54 | body = models.TextField() |
| 55 | pub_date = models.DateTimeField() |
| 56 | |
| 57 | class Meta: |
| 58 | ordering = ('pub_date','headline') |
| 59 | |
| 60 | def __str__(self): |
| 61 | return self.headline |
| 62 | |
| 63 | __test__ = {'API_TESTS':""" |
| 64 | # Create a couple of Articles. |
| 65 | >>> from datetime import datetime |
| 66 | >>> a = Article(headline='Article 1', body='Body 1', pub_date=datetime(2007, 5, 5)) |
| 67 | >>> a.save() |
| 68 | |
| 69 | # Change headline and body on different instances, then save both to verify |
| 70 | # that each only updated the modified field |
| 71 | >>> a1 = Article.objects.get(pk=a.id) |
| 72 | >>> a2 = Article.objects.get(pk=a.id) |
| 73 | >>> a1.headline = 'Changed article 1' |
| 74 | >>> a2.body = 'Changed body 1' |
| 75 | >>> a1.save() |
| 76 | >>> a2.save() |
| 77 | >>> a3 = Article.objects.get(pk=a.id) |
| 78 | >>> a3.headline |
| 79 | 'Changed article 1' |
| 80 | >>> a3.body |
| 81 | 'Changed body 1' |
| 82 | """} |
| 83 | """ |
| 84 | #. Save only modified fields on update |
| 85 | """ |
| 86 | from django.db import models |
| 87 | |
| 88 | class Article(models.Model): |
| 89 | headline = models.CharField(maxlength=100, default='Default headline') |
| 90 | body = models.TextField() |
| 91 | pub_date = models.DateTimeField() |
| 92 | |
| 93 | class Meta: |
| 94 | ordering = ('pub_date','headline') |
| 95 | |
| 96 | def __str__(self): |
| 97 | return self.headline |
| 98 | |
| 99 | __test__ = {'API_TESTS':""" |
| 100 | # Create a couple of Articles. |
| 101 | >>> from datetime import datetime |
| 102 | >>> a = Article(headline='Article 1', body='Body 1', pub_date=datetime(2007, 5, 5)) |
| 103 | >>> a.save() |
| 104 | |
| 105 | # Change headline and body on different instances, then save both to verify |
| 106 | # that each only updated the modified field. |
| 107 | >>> a1 = Article.objects.get(pk=a.id) |
| 108 | >>> a2 = Article.objects.get(pk=a.id) |
| 109 | >>> a1.headline = 'Changed article 1' |
| 110 | >>> a2.body = 'Changed body 1' |
| 111 | >>> a1.save() |
| 112 | >>> a2.save() |
| 113 | >>> a3 = Article.objects.get(pk=a.id) |
| 114 | >>> a3.headline |
| 115 | u'Changed article 1' |
| 116 | >>> a3.body |
| 117 | u'Changed body 1' |
| 118 | |
| 119 | # Fields entered at istantiation of a model which will already exists should be |
| 120 | # saved as well. |
| 121 | >>> a = Article(id=a.id, headline='Reset article 1', body='Reset body 1', pub_date=datetime(2007, 5, 5)) |
| 122 | >>> a.save() |
| 123 | >>> a3 = Article.objects.get(pk=a.id) |
| 124 | >>> a3.headline |
| 125 | u'Reset article 1' |
| 126 | >>> a3.body |
| 127 | u'Reset body 1' |
| 128 | """} |
| 129 | """ |
| 130 | #. Save only modified fields on update |
| 131 | """ |
| 132 | from django.db import models |
| 133 | |
| 134 | class Article(models.Model): |
| 135 | headline = models.CharField(maxlength=100, default='Default headline') |
| 136 | body = models.TextField() |
| 137 | pub_date = models.DateTimeField() |
| 138 | |
| 139 | class Meta: |
| 140 | ordering = ('pub_date','headline') |
| 141 | |
| 142 | def __str__(self): |
| 143 | return self.headline |
| 144 | |
| 145 | __test__ = {'API_TESTS':""" |
| 146 | # Create a couple of Articles. |
| 147 | >>> from datetime import datetime |
| 148 | >>> a = Article(headline='Article 1', body='Body 1', pub_date=datetime(2007, 5, 5)) |
| 149 | >>> a.save() |
| 150 | |
| 151 | # Change headline and body on different instances, then save both to verify |
| 152 | # that each only updated the modified field |
| 153 | >>> a1 = Article.objects.get(pk=a.id) |
| 154 | >>> a2 = Article.objects.get(pk=a.id) |
| 155 | >>> a1.headline = 'Changed article 1' |
| 156 | >>> a2.body = 'Changed body 1' |
| 157 | >>> a1.save() |
| 158 | >>> a2.save() |
| 159 | >>> a3 = Article.objects.get(pk=a.id) |
| 160 | >>> a3.headline |
| 161 | 'Changed article 1' |
| 162 | >>> a3.body |
| 163 | 'Changed body 1' |
| 164 | """} |