| 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 | 'Changed article 1' |
| 34 | >>> a3.body |
| 35 | 'Changed body 1' |
| 36 | """} |
| 37 | """ |
| 38 | #. Save only modified fields on update |
| 39 | """ |
| 40 | from django.db import models |
| 41 | |
| 42 | class Article(models.Model): |
| 43 | headline = models.CharField(maxlength=100, default='Default headline') |
| 44 | body = models.TextField() |
| 45 | pub_date = models.DateTimeField() |
| 46 | |
| 47 | class Meta: |
| 48 | ordering = ('pub_date','headline') |
| 49 | |
| 50 | def __str__(self): |
| 51 | return self.headline |
| 52 | |
| 53 | __test__ = {'API_TESTS':""" |
| 54 | # Create a couple of Articles. |
| 55 | >>> from datetime import datetime |
| 56 | >>> a = Article(headline='Article 1', body='Body 1', pub_date=datetime(2007, 5, 5)) |
| 57 | >>> a.save() |
| 58 | |
| 59 | # Change headline and body on different instances, then save both to verify |
| 60 | # that each only updated the modified field |
| 61 | >>> a1 = Article.objects.get(pk=a.id) |
| 62 | >>> a2 = Article.objects.get(pk=a.id) |
| 63 | >>> a1.headline = 'Changed article 1' |
| 64 | >>> a2.body = 'Changed body 1' |
| 65 | >>> a1.save() |
| 66 | >>> a2.save() |
| 67 | >>> a3 = Article.objects.get(pk=a.id) |
| 68 | >>> a3.headline |
| 69 | 'Changed article 1' |
| 70 | >>> a3.body |
| 71 | 'Changed body 1' |
| 72 | """} |
| 73 | """ |
| 74 | #. Save only modified fields on update |
| 75 | """ |
| 76 | from django.db import models |
| 77 | |
| 78 | class Article(models.Model): |
| 79 | headline = models.CharField(maxlength=100, default='Default headline') |
| 80 | body = models.TextField() |
| 81 | pub_date = models.DateTimeField() |
| 82 | |
| 83 | class Meta: |
| 84 | ordering = ('pub_date','headline') |
| 85 | |
| 86 | def __str__(self): |
| 87 | return self.headline |
| 88 | |
| 89 | __test__ = {'API_TESTS':""" |
| 90 | # Create a couple of Articles. |
| 91 | >>> from datetime import datetime |
| 92 | >>> a = Article(headline='Article 1', body='Body 1', pub_date=datetime(2007, 5, 5)) |
| 93 | >>> a.save() |
| 94 | |
| 95 | # Change headline and body on different instances, then save both to verify |
| 96 | # that each only updated the modified field |
| 97 | >>> a1 = Article.objects.get(pk=a.id) |
| 98 | >>> a2 = Article.objects.get(pk=a.id) |
| 99 | >>> a1.headline = 'Changed article 1' |
| 100 | >>> a2.body = 'Changed body 1' |
| 101 | >>> a1.save() |
| 102 | >>> a2.save() |
| 103 | >>> a3 = Article.objects.get(pk=a.id) |
| 104 | >>> a3.headline |
| 105 | 'Changed article 1' |
| 106 | >>> a3.body |
| 107 | 'Changed body 1' |
| 108 | """} |
| 109 | """ |
| 110 | #. Save only modified fields on update |
| 111 | """ |
| 112 | from django.db import models |
| 113 | |
| 114 | class Article(models.Model): |
| 115 | headline = models.CharField(maxlength=100, default='Default headline') |
| 116 | body = models.TextField() |
| 117 | pub_date = models.DateTimeField() |
| 118 | |
| 119 | class Meta: |
| 120 | ordering = ('pub_date','headline') |
| 121 | |
| 122 | def __str__(self): |
| 123 | return self.headline |
| 124 | |
| 125 | __test__ = {'API_TESTS':""" |
| 126 | # Create a couple of Articles. |
| 127 | >>> from datetime import datetime |
| 128 | >>> a = Article(headline='Article 1', body='Body 1', pub_date=datetime(2007, 5, 5)) |
| 129 | >>> a.save() |
| 130 | |
| 131 | # Change headline and body on different instances, then save both to verify |
| 132 | # that each only updated the modified field |
| 133 | >>> a1 = Article.objects.get(pk=a.id) |
| 134 | >>> a2 = Article.objects.get(pk=a.id) |
| 135 | >>> a1.headline = 'Changed article 1' |
| 136 | >>> a2.body = 'Changed body 1' |
| 137 | >>> a1.save() |
| 138 | >>> a2.save() |
| 139 | >>> a3 = Article.objects.get(pk=a.id) |
| 140 | >>> a3.headline |
| 141 | 'Changed article 1' |
| 142 | >>> a3.body |
| 143 | 'Changed body 1' |
| 144 | """} |
| 145 | """ |
| 146 | #. Save only modified fields on update |
| 147 | """ |
| 148 | from django.db import models |
| 149 | |
| 150 | class Article(models.Model): |
| 151 | headline = models.CharField(maxlength=100, default='Default headline') |
| 152 | body = models.TextField() |
| 153 | pub_date = models.DateTimeField() |
| 154 | |
| 155 | class Meta: |
| 156 | ordering = ('pub_date','headline') |
| 157 | |
| 158 | def __str__(self): |
| 159 | return self.headline |
| 160 | |
| 161 | __test__ = {'API_TESTS':""" |
| 162 | # Create a couple of Articles. |
| 163 | >>> from datetime import datetime |
| 164 | >>> a = Article(headline='Article 1', body='Body 1', pub_date=datetime(2007, 5, 5)) |
| 165 | >>> a.save() |
| 166 | |
| 167 | # Change headline and body on different instances, then save both to verify |
| 168 | # that each only updated the modified field |
| 169 | >>> a1 = Article.objects.get(pk=a.id) |
| 170 | >>> a2 = Article.objects.get(pk=a.id) |
| 171 | >>> a1.headline = 'Changed article 1' |
| 172 | >>> a2.body = 'Changed body 1' |
| 173 | >>> a1.save() |
| 174 | >>> a2.save() |
| 175 | >>> a3 = Article.objects.get(pk=a.id) |
| 176 | >>> a3.headline |
| 177 | 'Changed article 1' |
| 178 | >>> a3.body |
| 179 | 'Changed body 1' |
| 180 | """} |