TCS Wings 1 T4 Django - Set 10
- 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) Usepermissions.IsAuthenticated
b) Overrideget_queryset()method in the view
c) UseAllowAnypermission
d) Filter by user in the serializer
Answer: b) Override get_queryset() method in the view
- 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
- You need to retrieve the first object from a Django ORM queryset, or return
Noneif no objects are found. Which method should you use?
a)get()
b)first()
c)last()
d)filter()
Answer: b) first()
- 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
- 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 theviews.pyfile
b) In themodels.pyfile using@property
c) In theserializers.pyfile
d) In the database schema
Answer: b) In the models.py file using @property
- 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) Setunique=Trueon the ID field in the model
b) Override thesave()method in the serializer
c) Set theread_onlyflag for the ID field in the serializer
d) Useunique_togetherin the model
Answer: a) Set unique=True on the ID field in the model
- 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()
- You need to provide pagination support for your Django Rest Framework API. How can you configure pagination globally for all API views?
a) SetPAGINATE_BYin the view
b) AddDEFAULT_PAGINATION_CLASSinsettings.py
c) Overridepaginate_queryset()in each view
d) Use a custom pagination class
Answer: b) Add DEFAULT_PAGINATION_CLASS in settings.py
- 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 theurls.pyfile
b) In a customauthenticate()method in the backend
c) In theforms.pyfile
d) Insettings.py
Answer: b) In a custom authenticate() method in the backend
- You need to perform a full-text search on a
CharFieldin 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
Post a Comment