> For the complete documentation index, see [llms.txt](https://olee-tech.gitbook.io/django/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://olee-tech.gitbook.io/django/django-orm/advanced-querying-with-django-orm/q-objects.md).

# Q() Objects

**AND, OR, NOT এই জাতীয় কমপ্লেক্স কোয়েরি করার জন্য Q() ব্যবহার করা হয়।**

```python
from django.db import models

class Book(models.Model):
    title = models.CharField(max_length=100)
    author = models.CharField(max_length=50)
    published_year = models.PositiveIntegerField()
    genre = models.CharField(max_length=50)
```

**OR** **Example**

```python
from django.db.models import Q

# Retrieve books that match the criteria
books = Book.objects.filter(Q(published_year__gte=2000) | Q(genre='Science Fiction'))

```

**And Example**

```
# Retrieve books that match both conditions using AND
books = Book.objects.filter(Q(published_year__gte=2000) & Q(genre='Science Fiction'))
```

**NOT Example**

```python
from django.db.models import Q

# Retrieve books that do not match the condition using NOT
books = Book.objects.filter(~Q(published_year__gte=2000))
```

###
