TCS Wings 1 T4 Django - Set 9
- You are building a Django Rest Framework API that allows users to upload files. You want to set a limit on the file types that can be uploaded. Where should you enforce this restriction?
a) In theviews.pyfile
b) In themodels.pyfile
c) In theserializers.pyfile using a custom validator
d) In thesettings.pyfile
Answer: c) In the serializers.py file using a custom validator
- You want to run specific actions after an instance is saved in Django ORM, such as sending a notification. Which method should you override in the model to achieve this?
a)pre_save()
b)post_save()
c)save()
d)clean()
Answer: c) save()
- In a Django Rest Framework project, you need to validate input data before saving it to the database. Which method should you override in your serializer class?
a)save()
b)validate()
c)is_valid()
d)create()
Answer: b) validate()
- You are building a Django project that uses a large number of related models. To improve query performance when accessing related objects, which method should you use?
a)prefetch_related()
b)select_related()
c)annotate()
d)order_by()
Answer: b) select_related()
- In your Django Rest Framework project, you want to handle different media types in your API response, such as JSON and XML. How do you achieve this?
a) UseDEFAULT_RENDERER_CLASSESinsettings.py
b) Set aContentTypeheader in views
c) Overrideget_serializer()method
d) UseContentNegotiationclass
Answer: a) Use DEFAULT_RENDERER_CLASSES in settings.py
- You are creating a REST API in Django Rest Framework and want to send email notifications when a new user registers. Where should you implement this functionality?
a) In theviews.pyfile
b) In themodels.pyfile using signals
c) In theserializers.pyfile
d) Insettings.py
Answer: b) In the models.py file using signals
- In Django ORM, you need to query for records that contain a specific substring in a text field. Which lookup should you use?
a)contains
b)exact
c)startswith
d)endswith
Answer: a) contains
- Your Django Rest Framework project requires you to authenticate users using JWT tokens. Which library would you use to implement JWT-based authentication in DRF?
a)rest_framework_simplejwt
b)djangorestframework-jwt
c)django-rest-auth
d)oauthlib
Answer: a) rest_framework_simplejwt
- You need to perform a bulk update on multiple records in Django ORM in a single query. Which method should you use?
a)bulk_update()
b)update()
c)save()
d)create()
Answer: a) bulk_update()
- In your Django Rest Framework API, you want to return different responses for users with different roles (e.g., admin, regular user). How can you achieve this?
a) Override theget()method in the view
b) Use a custom permission class
c) Check the user role in the serializer
d) Useis_valid()to differentiate roles
Answer: b) Use a custom permission class

Comments
Post a Comment