Posts

TCS Wings 1 T4 Django - Set 10

Image
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 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 None if 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) Aut...

TCS Wings 1 T4 Django - Set 9

Image
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 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, wh...

TCS Wings 1 T4 Django - Set 8

Image
In Django ORM, how can you prefetch related objects to optimize database queries for many-to-many relationships? a) select_related() b) annotate() c) values() d) prefetch_related() Answer: d) prefetch_related() You want to define custom actions for a Django Rest Framework ModelViewSet . Where should you define these custom actions? a) In the serializer b) In the urls.py file c) In the viewset using @action decorator d) In the model Answer: c) In the viewset using @action decorator Your Django project needs to send a confirmation email to users after they register. Which Django feature would you use to send emails? a) Django Celery b) Django Signals c) Django Email Backend d) Django Tasks Answer: c) Django Email Backend You are implementing a JWT-based authentication system for your API. How would you securely store the JWT token on the client-side? a) Store it in local storage b) Store it in a session cookie with HttpOnly flag c) Include it in the URL parameters d) Store it in a ...

TCS Wings 1 T4 Django - Set 7

Image
You are developing an API in Django Rest Framework where you want to return paginated results for a list of items. How can you add pagination globally to your API views? a) Set PAGINATE_BY in the view b) Add pagination settings in settings.py c) Use PageNumberPagination in each view d) Define a custom pagination class Answer: b) Add pagination settings in settings.py You want to query the last 10 records of a model in Django ORM, sorted by creation date. Which method would you use? a) Model.objects.filter().limit(10) b) Model.objects.all()[:10] c) Model.objects.order_by('-created_at')[:10] d) Model.objects.last(10) Answer: c) Model.objects.order_by('-created_at')[:10] In your Django project, you want to implement caching for API responses to improve performance. Which middleware should you use to add caching? a) SessionMiddleware b) CacheMiddleware c) SecurityMiddleware d) CorsMiddleware Answer: b) CacheMiddleware In Django ORM, how do you retrieve only distinct va...

TCS Wings 1 T4 Django - Set 6

Image
You need to create a Django Rest Framework API that restricts access to authenticated users only. Which permission class should you use to enforce this? a) IsAdminUser b) IsAuthenticated c) AllowAny d) IsAuthenticatedOrReadOnly Answer: b) IsAuthenticated In your Django project, you want to retrieve objects in batches to improve performance for large datasets. Which Django ORM function should you use? a) all() b) filter() c) iterator() d) get() Answer: c) iterator() You want to ensure that only users with an active status can log in to your Django application. How do you enforce this in Django Rest Framework? a) Override the login() view b) Use IsAuthenticated permission c) Override the authenticate() method d) Set a custom user model and check the is_active flag Answer: d) Set a custom user model and check the is_active flag In Django ORM, how can you exclude specific objects from a query result? a) Use filter() with NOT condition b) Use exclude() c) Use annotate() d) Use excl...

TCS Wings 1 T4 Django - Set 5

Image
In your Django application, you need to restrict access to views based on the user’s role. How do you define role-based access control in Django Rest Framework? a) Use IsAuthenticated permission class b) Define custom permission classes c) Add user role checks in urls.py d) Use the login_required decorator Answer: b) Define custom permission classes You are working on a Django project where you need to create a custom management command. Which directory structure is appropriate for defining custom management commands in a Django app? a) app/management/commands/ b) app/utils/commands/ c) app/views/commands/ d) app/templates/commands/ Answer: a) app/management/commands/ You have a Django Rest Framework viewset where different user roles have different access levels. How do you define permissions for different actions such as list() , create() , and delete() ? a) Use IsAuthenticated globally b) Set permissions in the urls.py c) Use get_permissions() to define different permissions f...

TCS Wings 1 T4 Django - Set 4

Image
You are designing a multi-tenant Django application where each user should only have access to their own data. How do you filter queryset results to ensure this security? a) Implement filtering in the templates b) Use get_object_or_404() with user data c) Override the get_queryset() method to include user-specific filtering d) Use get_context_data() in class-based views Answer: c) Override the get_queryset() method to include user-specific filtering In your Django application, users can belong to multiple groups. How do you represent this relationship in your model? a) Use a OneToOneField b) Use a ForeignKey c) Use a ManyToManyField d) Use a CharField with choices Answer: c) Use a ManyToManyField You want to add pagination to a Django Rest Framework API to display 20 items per page. How do you configure this? a) Set PAGINATE_BY in the view b) Set PAGINATE_BY_PARAM in the view c) Configure PAGE_SIZE in settings d) Use max_limit in the view Answer: c) Configure PAGE_SIZE in se...