Top 50 Django Object Relational Mapper Questions and Answers

Django Object Relational Mapper

Q.1 Choose the correct option to create an app ‘myapp’.

       A. python manage.py start myapp

       B. python manage.py startproject myapp

       C. python manage.py startapp myapp

       D. python manage.py myapp

Ans : python manage.py startapp myapp


Q.2 A Django app will contain _____.

       A. views.py

       B. tests.py

       C. apps.py

       D. models.py

       E. All the options

Ans : All the options


Q.3 Choose the correct option to create a project myworld using the Django-admin command.

       A. $ django-admin createproject myworld

       B. $ django-admin create myworld

       C. $ django-admin startproject myworld

       D. $ django-admin start myworld

Ans : $ django-admin startproject myworld


Q.4 Select the incorrect statement.

       A. A project can have multiple apps

       B. A project can have a single application

       C. One app can be in multiple projects

       D. None of the options

Ans : A project can have multiple apps


Q.5 Which setting can be used while adding a new Django app?

       A. DYNAMIC_APPS

       B. ADD_APPS

       C. INSTALLED_APPS

       D. CREATE_APPS

Ans : INSTALLED_APPS


Q.6 Select the incorrect statement: Django ORM.

       A. Auto generates primary keys

       B. Efficient for simple and medium databases

       C. Autocommit transactions

       D. Supports SQLite only

Ans : Supports SQLite only


Q.7 Object-relational Mapper (ORM) is a code library to automate the data transfer between _______.

       A. Databases and Objects

       B. Objects and Arrays

       C. Databases and Arrays

       D. Relational DB and Objects

Ans : Relational DB and Objects


Q.8 Identify the ORM most used for Flask Web Framework.

       A. peewee

       B. SQLAlchemy

       C. Hibernate

       D. Django’s ORM

Ans : SQLAlchemy


Q.9 What is/are applicable for Django ORM?

       A. Shifting complexity from the database into the application code

       B. Potential for reduced performance

       C. Impedance mismatch

       D. All the options

Ans : All the options


Q.10 id- is the auto assigned primary key by Django with the datatype.

       A. models.FloatField()

       B. models.TextField()

       C. models.AutoField()

       D. models.IntegerField()

Ans : models.AutoField()


Q.11 What are the different ways of connecting multiple models relationship?

       A. One-to-one

       B. Many-to-one

       C. Many-to-many

       D. All the options

Ans : All the options

Learn more on Django Object Relational Interview Questions


Q.12 To rename the Manager for a given class, what attribute type can be used in models.Manager() on that model?

       A. objects

       B. Customer

       C. filter

       D. class

Ans : class

Q.13 A Django model is a Python class that subclasses _________.

       A. djangodb.models.Model

       B. django.db.model.Models

       C. djangodb.model.Models

       D. django.db.models.Model

Ans : django.db.models.Model


Q.14 When choosing field names for the model, it should not conflict with the model API. The field name should not be _________.

       A. clean

       B. clean, save and delete

       C. save and delete

       D. delete

       E. save

       F. clean and save

Ans : clean, save and delete


Q.15 What exception is an attribute of each model class?

       A. ClassDoesnotExist

       B. AttributeDoesnotExist

       C. ObjectDoesnotExist

       D. DoesnotExist

Ans : DoesnotExist


Q.16 What can be used to provide custom model validation and to modify attributes on the model like changing the value on a field upon a conditional check?

       A. Model.full_clean()

B. Model.clean()

       C. Model.validate_unique(exclude=None)

       D. Model.clean_fields(exclude=None)

Ans : Model.clean()


Q.17 What can be used to validate all model fields, if any field is to be exempted from validation? Provide it in the exclude parameter.

       A. Model.clean()

       B. Model.clean_fields(exclude=None)

       C. Model.full_clean()

       D. Model.validate_unique(exclude=None)

Ans : Model.clean_fields(exclude=None)


Q.18 What can be used to validate all unique constraints on the model instead of individual field values?

       A. Model.clean()

       B. Model.clean_fields(exclude=None)

       C. Model.full_clean()

       D. Model.validate_unique(exclude=None)

Ans : Model.validate_unique(exclude=None)


Q.19 When an object is saved, Django _____________.

       A. emits a pre save signal

       B. emit a post save signal

       C. prepares data for the database

       D. preprocesses the data

       E. inserts data into database

       F. all the options

Ans : all the options


Q.20 Select the incorrect statement about A QuerySet.

       A. Can have filters to obtain different query results

       B. Is a collection of database objects

       C. Incomparable to a database select operation

       D. Can be operated on a model

Ans : Incomparable to a database select operation


Q.21 Select the incorrect statement: QuerySet API are classified as _________.

       A. Methods that return new QuerySets

       B. Field Lookups

       C. Methods that do not return QuerySets

       D. Methods that return new querysets’ AND ‘field lookups’ AND ‘aggregation functions’

E. Aggregation funcions

       F. all the options

Ans : all the options


Q.22 Django is loaded with a database-abstraction API to ______.

       A. update and delete objects

       B. create objects

       C. retrieve objects

       D. all the options

Ans : all the options


Q.23 Data migrations _________.

       A. alter data

       B. use RunPython operation that takes a callable as argument

       C. custom written unlike schema migrations

       D. all the options

Ans : all the options


Q.24 Table names in databases are created by default with app_classname.

       A. True

       B. False

Ans : True


Q.25 exclude(**kwargs) – Returns QuerySet containing objects matching given lookup parameters.

       A. True

       B. False

Ans : False

Django Object-Relational Mapper MCQs Part2

Q.1 Select the incorrect statement: Migration Operations ________.

       A. records history of model changes

       B. runs through models without touching database

       C. migrations aren’t automatically done based on history of model changes

       D. helps to load models to memory

Ans : migrations aren’t automatically done based on history of model changes


Q.2 How to make a migration run outside transaction in a DDL based transaction?

       A. database files

       B. migration files

       C. database objects

       D. text files

Ans : migration files

Learn more on Django Object Relational Questions and Answers


Q.3 How to make a migration run outside transaction in a DDL based transaction?

       A. class Migration(migrations.Migration):
  atomic = False

       B. class Migration(migrations.Migration):
  atomic = True

       C. class Migration(migrations):
  atomic = False

       D. class Migration(migrations):
  atomic = True

Ans : class Migration(migrations.Migration):
  atomic = False


Q.4 Select the incorrect statement: Database Transaction ________.

       A. is started by enabling autocommit using set_autocommit()

       B. use commit() to apply the changes

       C. is an atomic set of database queries which applies either all or no changes to the data

       D. use rollback() to cancel the changes

Ans : is started by enabling autocommit using set_autocommit()

Q.5 Schema Migrations-run custom SQL using RunSQL or python code blocks using RunPython.

       A. True

       B. False

Ans : False


Q.6 The integrity of Django ORM operations involving multiple queries can be achieved through savepoints.

       A. True

       B. False

Ans : True


Q.7 What exception is raised, if the primary key is excluded from a Raw query?

       A. InvalidField exception

       B. InvalidAttribute exception

       C. InvalidQuery exception

       D. InvalidObject exception

Ans : InvalidQuery exception


Q.8 Select the incorrect statement: A database Router uses the method ________.

       A. allow_migrate(db, app_label, model_name=None, **hints)

       B. db_for_delete(model, **hints)

       C. allow_relation(obj1, obj2, **hints)

       D. db_for_write(model, **hints)

Ans : db_for_delete(model, **hints)


Q.9 What represents the logic layer of the program?

       A. VIEWS

       B. TEMPLATES

C. MODELS

       D. CONTROLLERS

Ans : TEMPLATES


Q.10 Name the incorrect field option.

       A. blank

       B. null

       C. choices

       D. None of the options

Ans : blank


Q.11 Which is not an aggregation function?

       A. variance

       B. sum

       C. filter

       D. range

Ans : filter


Q.12 Identify the incorrect option: Method that does not return a new queryset.

       A. difference()

       B. exists()

       C. first()

       D. delete()

Ans : difference()


Q.13 Django helps to tackle ________.

       A. Cross-site scripting

       B. cross-site request forgery and clickjacking

       C. SQL injection

       D. All the options

Ans : All the options


Q.14 What do you call a migration that creates the first version of the app’s tables?

       A. start migration

       B. default migration

       C. initial migration

       D. first migration

Ans : initial migration


Q.15 Migrations usually Create the required scripts to change the structure by updating the code and changing your models.

       A. True

       B. False

Ans : True


Q.16 filter(**kwargs) – Returns QuerySet containing objects that do not match the given lookup parameters.

       A. True

       B. False

Ans : True


Q.17 Manager.raw() supports indexing.

       A. True

       B. False

Ans : True


Q.18 Connection and cursor mostly implement the standard Python DB-API.

 A. True

       B. False

Ans : True


Q.19 Identify the incorrect field lookup option.

       A. regex

       B. exact

       C. lte

       D. month

Ans : regex


Q.20 The ‘OR’ condition in queryset is possible because of using _____.

       A. F() object

       B. Q object AND F object

       C. Q() object

       D. None of the options

Ans : Q object AND F object


Q.21 Identify the incorrect option: Method that returns a new queryset.

       A. earliest()

       B. union()

       C. raw()

       D. none()

Ans : none()


Q.22 What is the act of reducing a set of migrations to one or few?

       A. optimize

       B. Squashing

       C. reduce

       D. None of the options

Ans : Squashing


Q.23 Which is not a python ORM implementation?

       A. Storm

       B. SQLAlchemy

       C. PonyORM

       D. hibernate

Ans : SQLAlchemy


Q.24 Which applies the changes till savepoint to the transaction and releases the SID?

A. savepoint_commit(sid, using=None)

       B. savepoint_rollback(sid, using=None)

       C. savepoint(using=None)

       D. None of the options

Ans : savepoint_rollback(sid, using=None)

Learn more on Django Object Relational Multiple Choice Questions


Q.25 Name the comparison and conversion database functions.

       A. Least

       B. Greatest

       C. Cast

       D. Coalesce

Ans : Cast


Q.26 To limit a queryset result to return objects from 4th through 8th object, use ________.

       A. Mymodel.objects.all()[4:8]

       B. Mymodel.objects.all()[:8]

       C. Mymodel.objects.all()[3:8]

       D. Mymodel.objects.all()[4:]

Ans : Mymodel.objects.all()[3:8]

Click here to read more Blogs

Click here to read more technical Interview Questions and Answers

Click here to read more Technical Q&A

About Author


After years of Technical Work, I feel like an expert when it comes to Develop wordpress website. Check out How to Create a Wordpress Website in 5 Mins, and Earn Money Online Follow me on Facebook for all the latest updates.

Leave a Comment