7.1. ORM About
7.1.1. Create Objects
.bulk_create().create().get_or_create().save().update_or_create()
7.1.2. Update Objects
.bulk_update().save().select_for_update().update().update_or_create()
7.1.3. Delete Objects
.delete()
7.1.4. Get One Result
.earliest().first().get().get_or_create().last().latest()
7.1.5. Get Many Result
.all().complex_filter().extra().filter().reverse().union()
7.1.6. Narrow Results
.exclude().intersection().none().only().values().values_list()result[1:]result[1]result[::2]
7.1.7. Check Results
.check().exist().exists().explain()
7.1.8. Order Results
.order_by()
7.1.9. Performance
.prefetch_related().select_related()
7.1.10. Functions
.aggregate().alias().annotate().count().distinct().using()
7.1.11. Other
.dates().datetimes().difference().in_bulk().raw()
7.1.12. Lookup
Empty:
__isnull
Sequences:
__in
Strings:
__contains- case sensitive__endswith- case sensitive__exact- case sensitive (default)__icontains- case insensitive__iendswith- case insensitive__iexact- case insensitive__istartswith- case insensitive__startswith- case sensitive
Numeric, Dates:
__eq- equals__gt- greater than__gte- greater or equal than__lt- less than__lte- less or eaquan than
Dates:
__year__month__day__hour__minute__second__microsecond__range- between two dates__in- a list of dates
7.1.13. Comparing objects
>>>
... my == other
... my.id == other.id
>>>
... my == other
... my.name == other.name