Table of Contents
23 Appendix C: Database API Reference
23.6 Field Lookups..............................................................................................................................289
23.6.1 exact....................................................................................................................................289
23.6.2 iexact..................................................................................................................................289
23.6.3 contains...............................................................................................................................289
23.6.4 icontains..............................................................................................................................290
23.6.5 gt, gte, lt, and lte.................................................................................................................290
23.6.6 in.........................................................................................................................................290
23.6.7 startswith............................................................................................................................290
23.6.8 istartswith...........................................................................................................................291
23.6.9 endswith and iendswith......................................................................................................291
23.6.10 range.................................................................................................................................291
23.6.11 year, month, and day........................................................................................................291
23.6.12 isnull.................................................................................................................................291
23.6.13 search................................................................................................................................292
23.6.14 The pk Lookup Shortcut...................................................................................................292
23.7 Complex Lookups with Q Objects...............................................................................................292
23.8 Related Objects............................................................................................................................293
23.8.1 Lookups That Span Relationships......................................................................................293
23.8.2 Foreign Key Relationships.................................................................................................294
23.8.3 “Reverse” Foreign Key Relationships................................................................................294
23.8.4 Many-to-Many Relationships.............................................................................................296
23.8.5 Queries Over Related Objects............................................................................................297
23.9 Deleting Objects...........................................................................................................................297
23.10 Extra Instance Methods..............................................................................................................297
23.10.1 get_FOO_display()...........................................................................................................297
23.10.2 get_next_by_FOO(**kwargs) and get_previous_by_FOO(**kwargs)...........................298
23.10.3 get_FOO_filename()........................................................................................................298
23.10.4 get_FOO_url()..................................................................................................................298
23.10.5 get_FOO_size()................................................................................................................298
23.10.6 save_FOO_file(filename, raw_contents)..........................................................................298
23.10.7 get_FOO_height() and get_FOO_width()........................................................................299
23.11 Shortcuts....................................................................................................................................299
23.11.1 get_object_or_404().........................................................................................................299
23.11.2 get_list_or_404()..............................................................................................................299
23.12 Falling Back to Raw SQL..........................................................................................................299
24 Appendix D: Generic View Reference.....................................................................................................300
24.1 Common Arguments to Generic Views.......................................................................................300
24.2 “Simple” Generic Views..............................................................................................................300
24.2.1 Rendering a Template........................................................................................................300
24.2.2 Redirecting to Another URL..............................................................................................301
24.3 List/Detail Generic Views............................................................................................................302
24.3.1 Lists of Objects...................................................................................................................302
24.3.2 Detail Views.......................................................................................................................303
24.4 Date-Based Generic Views..........................................................................................................305
24.4.1 Archive Index.....................................................................................................................305
24.4.2 Year Archives.....................................................................................................................306
24.4.3 Month Archives..................................................................................................................307
24.4.4 Week Archives...................................................................................................................309
24.4.5 Day Archives......................................................................................................................310
24.4.6 Archive for Today..............................................................................................................311
The Django Book
x