8.1. ORM Aboutï
8.1.1. Create Objectsï
.bulk_create().create().get_or_create().save().update_or_create()
8.1.2. Update Objectsï
.bulk_update().save().select_for_update().update().update_or_create()
8.1.3. Delete Objectsï
.delete()
8.1.4. Get One Resultï
.earliest().first().get().get_or_create().last().latest()
8.1.5. Get Many Resultï
.all().complex_filter().extra().filter().reverse().union()
8.1.6. Narrow Resultsï
.exclude().intersection().none().only().values().values_list()result[1:]result[1]result[::2]
8.1.7. Check Resultsï
.check().exist().exists().explain()
8.1.8. Order Resultsï
.order_by()
8.1.9. Performanceï
.prefetch_related().select_related()
8.1.10. Functionsï
.aggregate().alias().annotate().count().distinct().using()
8.1.11. Otherï
.dates().datetimes().difference().in_bulk().raw()
8.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
8.1.13. Comparing objectsï
>>> #
... my == other
... my.id == other.id
>>> #
... my == other
... my.name == other.name