Bird
0
0

What is wrong with this ModelSerializer definition?

medium📝 Debug Q14 of 15
Django - REST Framework Basics
What is wrong with this ModelSerializer definition?
class AuthorSerializer(serializers.ModelSerializer):
    class Meta:
        model = Author
        fields = 'name' 'email'
AFields should be a list or tuple inside brackets, not separate strings.
BModelSerializer cannot serialize Author model.
CMeta class must be outside the serializer class.
DFields must include '__all__' instead of specific names.
Step-by-Step Solution
Solution:
  1. Step 1: Check fields syntax

    Fields must be a list or tuple, e.g. ['name', 'email'] or ('name', 'email'), not separate strings without brackets.
  2. Step 2: Verify other options

    ModelSerializer can serialize any model, Meta must be nested, and fields can be specific names.
  3. Final Answer:

    Fields should be a list or tuple inside brackets, not separate strings. -> Option A
  4. Quick Check:

    Fields syntax requires brackets [OK]
Quick Trick: Fields must be list or tuple with brackets [OK]
Common Mistakes:
MISTAKES
  • Writing fields as comma-separated strings without brackets
  • Placing Meta class outside serializer
  • Thinking '__all__' is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes