TCS Wings 1 T4 Django - Set 9



  1. 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 the views.py file
    b) In the models.py file
    c) In the serializers.py file using a custom validator
    d) In the settings.py file

Answer: c) In the serializers.py file using a custom validator


  1. 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()


  1. 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()


  1. 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()


  1. 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) Use DEFAULT_RENDERER_CLASSES in settings.py
    b) Set a ContentType header in views
    c) Override get_serializer() method
    d) Use ContentNegotiation class

Answer: a) Use DEFAULT_RENDERER_CLASSES in settings.py


  1. 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 the views.py file
    b) In the models.py file using signals
    c) In the serializers.py file
    d) In settings.py

Answer: b) In the models.py file using signals


  1. 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


  1. 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


  1. 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()


  1. 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 the get() method in the view
    b) Use a custom permission class
    c) Check the user role in the serializer
    d) Use is_valid() to differentiate roles

Answer: b) Use a custom permission class

Comments

Popular posts from this blog

TCS Wings 1 T4 Django - Set 1

TCS Wings 1 T4 Django - Set 10

TCS Wings 1 T4 Django - Set 4