0
0
Djangoframework~10 mins

exclude() for negation in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aexclude
Ball
Cfilter
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() instead of exclude(), which returns matching records instead of excluding them.
2fill in blank
medium

Complete 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'
Afilter
Border_by
Cexclude
Dvalues
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() which returns only published posts instead of excluding them.
3fill in blank
hard

Fix 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'
Afilter
Bexclude
Cget
Dall
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() which returns only spam comments instead of excluding them.
4fill in blank
hard

Fill 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'
Aexclude
Bfilter
Corder_by
Dall
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() which would return only products matching the conditions instead of excluding them.
5fill in blank
hard

Fill 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'
Afilter
Bexclude
Corder_by
Dall
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() which would return only users matching the conditions instead of excluding them.