__exact: 정확히 일치하는 값
exact_match = Book.objects.filter(title__exact='Harry Potter')
__iexact: 대소문자 구분 없이 정확히 일치하는 값
iexact_match = Book.objects.filter(title__iexact='harry potter')
__contains: 부분 문자열이 포함된 경우
contains_match = Book.objects.filter(title__contains='Potter')
__icontains: 대소문자 구분 없이 부분 문자열이 포함된 경우
icontains_match = Book.objects.filter(title__icontains='potter')
__gt: 크다 (greater than)
greater_than = Book.objects.filter(published_date__gt='2020-01-01')
__gte: 크거나 같다 (greater than or equal to)
greater_or_equal = Book.objects.filter(published_date__gte='2020-01-01')
__lt: 작다 (less than)
less_than = Book.objects.filter(published_date__lt='2020-01-01')
__lte: 작거나 같다 (less than or equal to)
less_or_equal = Book.objects.filter(published_date__lte='2020-01-01')
__year: 특정 연도
year_filter = Book.objects.filter(published_date__year=2020)
__month: 특정 월
month_filter = Book.objects.filter(published_date__month=1)
__day: 특정 일
day_filter = Book.objects.filter(published_date__day=1)
__week: 특정 주
week_filter = Book.objects.filter(published_date__week=1)
__Range (범위) 필터링:
range_filter = Book.objects.filter(published_date__range=['2024-06-01', '2020-06-20'])
__isnull = True
null_filter = Book.objects.filter(author__isnull=True)
class Author(models.Model):
name = models.CharField(max_length=100)
class Book(models.Model):
title = models.CharField(max_length=200)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
related_filter = Book.objects.filter(author__name='J.K. Rowling')