TCS Wings 1 T4 Django - Set 10



  1. You are building a multi-tenant Django application where each user can only access their own data. How do you restrict access in Django Rest Framework?
    a) Use permissions.IsAuthenticated
    b) Override get_queryset() method in the view
    c) Use AllowAny permission
    d) Filter by user in the serializer

Answer: b) Override get_queryset() method in the view


  1. In your Django project, you want to schedule periodic tasks such as clearing expired sessions. Which library should you use to schedule these tasks?
    a) Django Signals
    b) Django Celery
    c) Django Cache
    d) Django Middleware

Answer: b) Django Celery


  1. You need to retrieve the first object from a Django ORM queryset, or return None if no objects are found. Which method should you use?
    a) get()
    b) first()
    c) last()
    d) filter()

Answer: b) first()


  1. In your Django Rest Framework project, you want to prevent users from making too many API requests within a short period. Which feature would you implement?
    a) Permission Classes
    b) Rate Limiting
    c) Authentication Classes
    d) Request Throttling

Answer: d) Request Throttling


  1. You need to create a custom field in a Django model that stores a calculated value based on other fields. Where should you define this logic?
    a) In the views.py file
    b) In the models.py file using @property
    c) In the serializers.py file
    d) In the database schema

Answer: b) In the models.py file using @property


  1. You are using Django Rest Framework to create an API where each resource has a unique identifier. How do you configure the serializer to ensure each resource has a unique ID?
    a) Set unique=True on the ID field in the model
    b) Override the save() method in the serializer
    c) Set the read_only flag for the ID field in the serializer
    d) Use unique_together in the model

Answer: a) Set unique=True on the ID field in the model


  1. In Django ORM, you want to create multiple related objects in a single transaction. Which method would you use to ensure atomicity?
    a) commit()
    b) bulk_create()
    c) transaction.atomic()
    d) save()

Answer: c) transaction.atomic()


  1. You need to provide pagination support for your Django Rest Framework API. How can you configure pagination globally for all API views?
    a) Set PAGINATE_BY in the view
    b) Add DEFAULT_PAGINATION_CLASS in settings.py
    c) Override paginate_queryset() in each view
    d) Use a custom pagination class

Answer: b) Add DEFAULT_PAGINATION_CLASS in settings.py


  1. Your Django application requires a custom login view where users can log in with their email address instead of their username. Where would you implement this custom authentication logic?
    a) In the urls.py file
    b) In a custom authenticate() method in the backend
    c) In the forms.py file
    d) In settings.py

Answer: b) In a custom authenticate() method in the backend


  1. You need to perform a full-text search on a CharField in your Django model. Which feature should you enable to optimize this search?
    a) select_related()
    b) prefetch_related()
    c) search_vector
    d) filter()

Answer: c) search_vector

Comments

Popular posts from this blog

TCS Wings 1 T4 Django - Set 1

TCS Wings 1 T4 Django - Set 4