Elance Django Test Answers 2015

What is the command to start Django's built-in development server?
manage.py runserver
manage.py --start
manage.py run
manage.py startserver --dev
manage.py --run

Given a model named 'User' that contains a DateTime field named 'last_login', how do you query for users that have never logged in?
User.objects.filter( last_login=Null )
User.objects.filter( last_login__null=True )
User.objects.filter( last_login__isnull=False )
User.objects.filter( last_login__isnull=True )
User.objects.filter( last_login=Never )

What does the Django command `manage.py shell` do?
Starts a command line in whatever $SHELL your environment uses.
Starts a Django command prompt with your Python environment pre-loaded.
Starts a Python command prompt with your Django environment pre-loaded.
Loads a special Pythonic version of the Bash shell.
Loads a Python command prompt you can use to sync your database schema remotely.

Assuming you've imported the proper Django model file, how do you add a 'User' model to the Django admin?
admin.register( Users )
admin.site( self, User )
user.site.register( Admin )
users.site.register( Admin )
admin.site.register( User )

What is the Django command to start a new app named 'users' in an existing project?
manage.py --newapp users
manage.py newapp users
manage.py --startapp users
manage.py startapp users
manage.py start users

What does a urls.py file do in Django?
This file contains site deployment data such as server names and ports.
It contains a site map of Django-approved URLs.
It contains URL matching patterns and their corresponding view methods.
You run this file when you get obscure 404 Not Found errors in your server logs.
This file provides an up to date list of how-to URLs for learning Django more easily.

What is the command to run Django's development server on port 8080 on IP address
manage.py --run 8080
manage.py --dev
manage.py runserver
manage.py run
manage.py runserver

Django is written using what programming language?

After you make a new 'app' in your existing Django project, how do you get Django to notice it?
No additional action is required, Django notices new apps automatically.
Run the `manage.py validate` command, and then start a new shell.
Run the `manage.py syncdb` command.
In settings.py, add the app to the PROJECT_APPS variable.
In settings.py, add the new app to the INSTALLED_APPS variable.

What is the purpose of settings.py?
To configure settings for the Django project
To configure settings for an app
To set the date and time on the server
To sync the database schema

How do you define a 'name' field in a Django model with a maximum length of 255 characters?
name = models.CharField(max_len=255)
name = models.CharField(max_length=255)
model = CharField(max_length=255)
name = model.StringField(max_length=auto)

What is the definition of a good Django app?
A good Django app provides a small, specific piece of functionality that can be used in any number of Django projects.
A good Django app is a fully functioning website that has 100% test coverage.
A good Django app is highly customized and cannot be used in multiple projects.

What is the most easiest, fastest, and most stable deployment choice in most cases with Django?

How do you exclude a specific field from a ModelForm?
Create a new Form, don't use a ModelForm
Use the exclude parameter in the Meta class in your form
Set the field to hidden
You can not do this

Assuming you have a Django model named 'User', how do you define a foreign key field for this model in another model?
model = new ForeignKey(User)
user = models.IntegerKey(User)
user = models.ForeignKey(User)
models.ForeignKey( self, User )

What preferred method do you add to a Django model to get a better string representation of the model in the Django admin?
to_s( self )

What is ModelForm used for?
To model an input form for a template
To specify rules for correct form when writing Django code
To define a form based on an existing model

What happens if MyObject.objects.get() is called with parameters that do not match an existing item in the database?
The Http404 exception is raised.
The DatabaseError exception is raised.
The MyObject.DoesNotExist exception is raised.
The object is created and returned.

A set of helpful applications to use within your Django projects is included in the official distribution. This module is called what?

What is the correct syntax for including a class based view in a URLconf?
(r'^pattern/$', YourView.as_view()),
(r'^pattern/$', YourView.init()),
(r'^pattern/$', YourView),
(r'^pattern/$', YourView()),

What is the command to start a new Django project called 'myproject'?
django-admin.py startproject myproject
django-admin.py --start myproject
django.py startproject myproject
django.py --new myproject
django.py new myproject

How to make django timezone-aware?
In settings.py: USE_L10N=True
in views.py, import timezone
in views.py, import tz
in urls.py, import timezone
In settings.py: USE_TZ=True

In Django how would you retrieve all the 'User' records from a given database?

How can you define additional behavior and characteristics of a Django class?
def setUp():
class Meta:
class __init__:
def Meta():
def __init__():

What is the Django shortcut method to more easily render an html response?

What does the Django command `manage.py validate` do?
Checks for errors in your views.
Checks for errors in your templates.
Checks for errors in your controllers.
Checks for errors in your models.
Checks for errors in your settings.py file.

What is the correct way to include django's admin urls? from django.contrib import admin') from django.conf.urls import patterns, include, url urlpatterns = patterns('', ______________________ )
url(r'^admin/', admin.as_view(), name='admin ),
url(r'^admin/', include(admin) ),
url(r'^admin/', include(admin.site.urls) ),
url(r'^admin/', admin.urls ),

Where is pre_save signal in Django
from django.db.models import pre_save
from django.db.models.signals import pre_save
There is no pre_save signal
from django.db.models.signal import pre_save

Given the Python data: mydata = [ [ 0, 'Fred' ], [ 1, 'Wilma' ] ] How do you access the data in a Django template?
{% for d in mydata %} <p><a href="/users/{% d.0 %}/">{% d.1 %}</a></p> {% endfor %}
{% for d in mydata -%} <p><a href="/users/{{ d.0 }}/">{{ d.1 }}</a></p> {% end -%}
{% for d in mydata %} <p><a href="/users/{{ d.0 }}/">{{ d.1 }}</a></p> {% endfor %}
{{ for d in mydata }} <p><a href="/users/{{ d[0] }}/">{{ d[1] }}</a></p> {{ endfor }}
{% mydata.each |d| %} <p><a href="/users/{{ d.1 }}/">{{ d.2 }}</a></p> {% end %}

What is the purpose of the STATIC_ROOT setting?
Defines the URL prefix where static files will be served from .
Defines the location where all static files will be copied by the 'collectstatic' management command, to be served by the production webserver.
A project's static assets should be stored here to be served by the development server.
Defines the location for serving user uploaded files.

How to create a DateTimeField named created and filled in only on the creation with the current time?
created = models.CreationTimeField()
created = models.DateTimeField(default=datetime.datetime.now())
created = models.DateTimeField(auto_now_add=True, auto_now=True)
created = models.DateTimeField(auto_now=True)
created = models.DateTimeField(auto_now_add=True)

Given an IntegerField named 'widgets' in the Django model 'User' , how do you calculate the average number of widgets per user?
User.objects.avg( 'widgets' )
Widget.objects.all().aggregate( Avg( 'users' ) )
User.all().aggregate( Avg( 'widgets' ) ).count()
User.objects.all().aggregate( Avg( 'widgets' ) )
User.objects.all().aggregate( Sum( 'widgets' ) )

What is the Django command to view a database schema of an existing (or legacy) database?
manage.py legacydb
django-admin.py schemadump
manage.py inspect
manage.py inspectdb
django-admin.py inspect

What is the Django command to retrieve the first 10 'User' records from your database sorted by name descending?

What is the definition of a Django Project?
A specific piece of functionality that can be used in multiple Django apps.
A fork of the official Django repo.
A web site that uses the Django framework.
A collection of configuration files and individual apps that form a web site.

Given a model named 'User' that contains a field named 'email', how do you perform a case-insensitive exact match for the email 'fred@aol.com'?
User.objects.filter( email__icontains='fred@aol.com' )
User.objects.filter( email__iexact='fred@aol.com' )
User.objects.filter( email__contains='fred@aol.com' )
User.objects.filter( email__exact='fred@aol.com' )
User.objects.filter( email__matches='fred@aol.com' )

Given a form with field foo, what should the validation method for this field be called?

You have created a Form class and wish to provide custom logic for validating the input in the "foo" field. What would you name your custom validation method?

When customizing validation in a Form subclass named MyForm, how do you add an error message that is displayed as a form-wide error?
Add the error to MyForm.errors in MyForm.clean()
Raise ValidationError in MyForm.clean_<fieldname>()
Raise ValidationError in MyForm.clean()
Add the error to MyForm._errors in MyForm.clean()

Which class is a model field representing a path to a server-based image file?

In settings.py, when DEBUG is set to ________, Django will email unhandled exceptional conditions.

What is the command used to print the CREATE TABLE SQL statements for the given app name?
./manage.py sql myapp
./manage.py schema myapp
./manage.py showsql myapp
django-admin.py dumpdata myapp
./manage.py showschema myapp

How do you create a recursive relationship in a model class named 'Company' in Django?

You have a Form defined with "password" and "confirm_password" fields. In what method of the "form" object would you validate that the values supplied in these fields match?

What command do you use to alter the fields Django displays for a given model in the Django admin ListView?

You can handle multiple Django forms with what keyword argument when creating forms?

Which of these can be used to retrieve a setting from the settings module, and provide a default if the setting is not defined?
get_setting("SETTING_NAME", default=default_value)
getattr("SETTING_NAME", settings, default=default_value)
settings.get("SETTING_NAME", default_value)
getattr(settings, "SETTING_NAME", default_value)

The Benevolent Dictators for Life of the Django Project are:
Ian Bicking and Jannis Leidel
Jacob Kaplan-Moss and Adrian Holovaty
and Armando De La Veloper
Guido van Rossum and Linus Torvalds
Eric S. Raymond and Larry Wall

The django.contrib.contenttypes application provides
functionality for working with varied file formats
mimetypes used for returning http responses
a generic interface for working with models
none of the others

In your django template, if you need to get the content of the block from the django parent template, what do you need to add? {% block my_block %} ___________ {% endblock %}
{% super %}
{{ extends block }}
super (block, self)__init__()
{{ block.super }}
{% block.super %}

Which type of custom template tag returns a string?

What command compile Django's translation files?
./manage.py translate_files
./manage.py compilei18n
./manage.py compilemessages
./manage.py i18n_update
./manage.py compiletranslation

A model's "full_clean()" method is called automatically when you call your model's "save()" method.

How would you perform a lookup on a model against a database aside from the default?

Given a model named 'User' that contains a CharField 'name', how do you query for users whose name starts with 'Fred' or 'Bob'?
User.objects.filter( name__regex=r'^(fred|bob)+' )
User.objects.filter( name_iregex=r'^(fred|bob)+' )
User.objects.filter( name__like=r'^(fred|bob)*' )
User.objects.filter( name__iregex=r'^(fred|bob).+' )
User.objects.filter( name__iregex=r'^(fred|bob)$' )

Which model field type does NOT exist in Django?

What datetime formatting would you apply in a template to display the following: 2013/03/20 8:00:06 AM ?
Y/m/d H:i
m/d/Y h:m:s
Y/m/d g:i:s A
Y-m-d H:m:s
Y/m/d H:i:s A

How would you create a ForeignKey from a model named Transaction, to a model named Product, with no reverse relation?
class Transaction(models.Model): product = models.ForeignKey(Product, related_name=None)
class Transaction(models.Model): product = models.ForeignKey(Product, related_name='+')
class Transaction(models.Model): product = models.ForeignKey(Product, related_name=False)
class Transaction(models.Model): product = models.ForeignKey(Product, related_name='')

How to set a default order by in your Django model ? YourModel.objects.all() will be ordered by default without calling order_by() method
Using META default_order attribute
Using META order attribute
Using META order_by attribute
Using META ordering attribute
Using META default_order_by attribute

What is the name of the Django decorator that hides sensitive info from error reports?

By using django.contrib.humanize, you can use the following filter in your template to display the number 3 as three.