Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to exclude all users with the username 'admin'.
Django
users = User.objects.[1](username='admin')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() instead of exclude(), which returns matching records instead of excluding them.
✗ Incorrect
The exclude() method returns a queryset excluding the records that match the condition.
2fill in blank
mediumComplete the code to exclude all posts that are published.
Django
posts = Post.objects.[1](status='published')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() which returns only published posts instead of excluding them.
✗ Incorrect
exclude() removes posts with status='published' from the queryset.
3fill in blank
hardFix the error in the code to exclude comments that are marked as spam.
Django
comments = Comment.objects.[1](is_spam=True)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() which returns only spam comments instead of excluding them.
✗ Incorrect
Using exclude(is_spam=True) returns comments that are not spam.
4fill in blank
hardFill both blanks to exclude all products that are either out of stock or discontinued.
Django
products = Product.objects.[1](stock=0).[2](discontinued=True)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() which would return only products matching the conditions instead of excluding them.
✗ Incorrect
Chaining exclude() calls removes products with stock=0 and those discontinued.
5fill in blank
hardFill all three blanks to exclude users who are staff, inactive, or have the role 'guest'.
Django
users = User.objects.[1](is_staff=True).[2](is_active=False).[3](role='guest')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() which would return only users matching the conditions instead of excluding them.
✗ Incorrect
Chaining exclude() removes users matching any of the unwanted conditions.