Bird
0
0

You want to create a DRF API that returns a list of users but only shows their email if the requesting user is an admin. Which advanced DRF feature helps achieve this cleanly?

hard📝 Application Q8 of 15
Django - DRF Advanced Features
You want to create a DRF API that returns a list of users but only shows their email if the requesting user is an admin. Which advanced DRF feature helps achieve this cleanly?
AUse default ModelSerializer without changes
BUse SerializerMethodField with a condition checking request user role
CUse throttling to restrict email access
DUse pagination to limit email visibility
Step-by-Step Solution
Solution:
  1. Step 1: Understand conditional field display need

    Showing email only to admins requires dynamic field logic.
  2. Step 2: Match feature to requirement

    SerializerMethodField allows custom logic per object and request.
  3. Final Answer:

    Use SerializerMethodField with a condition checking request user role -> Option B
  4. Quick Check:

    Conditional fields = SerializerMethodField [OK]
Quick Trick: SerializerMethodField enables conditional field display [OK]
Common Mistakes:
MISTAKES
  • Using pagination to hide fields
  • Confusing throttling with field control
  • Not customizing serializer for conditions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes