Changeset 7477 for django/trunk/tests/modeltests/lookup
- Timestamp:
- 04/26/08 21:50:16 (7 months ago)
- Files:
-
- django/trunk/tests/modeltests/lookup/models.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/tests/modeltests/lookup/models.py
r7322 r7477 163 163 Traceback (most recent call last): 164 164 ... 165 Field DoesNotExist: Article has no field named 'id_plus_two'165 FieldError: Cannot resolve keyword 'id_plus_two' into field. Choices are: headline, id, id_plus_one, pub_date 166 166 167 167 # If you don't specify field names to values(), all are returned. 168 168 >>> list(Article.objects.filter(id=5).values()) == [{'id': 5, 'headline': 'Article 5', 'pub_date': datetime(2005, 8, 1, 9, 0)}] 169 169 True 170 171 # values_list() is similar to values(), except that the results are returned as 172 # a list of tuples, rather than a list of dictionaries. Within each tuple, the 173 # order of the elemnts is the same as the order of fields in the values_list() 174 # call. 175 >>> Article.objects.values_list('headline') 176 [(u'Article 5',), (u'Article 6',), (u'Article 4',), (u'Article 2',), (u'Article 3',), (u'Article 7',), (u'Article 1',)] 177 178 >>> Article.objects.values_list('id').order_by('id') 179 [(1,), (2,), (3,), (4,), (5,), (6,), (7,)] 180 >>> Article.objects.values_list('id', flat=True).order_by('id') 181 [1, 2, 3, 4, 5, 6, 7] 182 183 >>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id') 184 [(1,), (2,), (3,), (4,), (5,), (6,), (7,)] 185 >>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id_plus_one', 'id') 186 [(2, 1), (3, 2), (4, 3), (5, 4), (6, 5), (7, 6), (8, 7)] 187 >>> Article.objects.extra(select={'id_plus_one': 'id+1'}).order_by('id').values_list('id', 'id_plus_one') 188 [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8)] 189 190 >>> Article.objects.values_list('id', 'headline', flat=True) 191 Traceback (most recent call last): 192 ... 193 TypeError: 'flat' is not valid when values_list is called with more than one field. 170 194 171 195 # Every DateField and DateTimeField creates get_next_by_FOO() and … … 241 265 >>> Article.objects.none().filter(headline__startswith='Article') 242 266 [] 267 >>> Article.objects.filter(headline__startswith='Article').none() 268 [] 243 269 >>> Article.objects.none().count() 244 270 0 … … 257 283 Traceback (most recent call last): 258 284 ... 259 TypeError: Cannot resolve keyword 'pub_date_year' into field. Choices are: id, headline, pub_date285 FieldError: Cannot resolve keyword 'pub_date_year' into field. Choices are: headline, id, pub_date 260 286 261 287 >>> Article.objects.filter(headline__starts='Article') 262 288 Traceback (most recent call last): 263 289 ... 264 TypeError: Cannot resolve keyword 'headline__starts' into field. Choices are: id, headline, pub_date 290 FieldError: Join on field 'headline' not permitted. 265 291 266 292 # Create some articles with a bit more interesting headlines for testing field lookups:
