Raghav
Django Trainer
HarshTechnologies
What is Django??
Scope of Django
Architecture
Models/Views/Templates
quiestions
Web framework:
Software designed to develop web application
Eq: CakePHP, Spring, Django
Server Side: PHP/Java/Python/Ruby/….
Client Side: HTML/HTML5/CSS/Javascript/Jquery/…
History:
2003, Django Software Foundation
20% market share in silicon valley, Second place after ruby
Developed with python
High-level framework for rapid web development
Complete stack of tools
Data modelled with Python classes ,
Manipulate data, CRUD
Production-ready data admin interface, generated dynamically
Elegant system for mapping URLs to Python code
Generic views’ to handle common requests
Clean, powerful template language
Components for user authentication, form handling, caching . . .
Django is a MVT arcitecture , more than MVC. /salaries
Models: Alice 50000
Modelling the classes according to the data Bob 20000
Cathy 35000
Views
query the data according to the request
Template
Represent/Structured the data in to the HTML template.
django-admin.py startproject
<PROJECT_ROOT>
manage.py
<PROJECT_DIR>
__init__.py
settings.py
urls.py
wsgi.py
django-admin startproject <projectname>
cd <projectname>
django-admin startapp <appname>
cd <appname>
A model is the single, definitive source of information about your data.
Essential fields and,
Behavior of data your are storing.
When defining a model ,
it is subclass of django.db.models.Model
each attribute defines database field.
Once you have defined your models, you need to
Tell DJANGO , use this model by add the ‘myapp’ in settings.py file under
‘INSTALLED_APPS’ section.
When ever any changes in the model, you should make sure to run manage.py migrate –
run-syncdb
It is the list of database fields it defines.
Fields are specified by class attributes.
Field Types:
Column type which tells the database what kind of data to store.
AutoField/BigAutoField GenericIPAddressField
BigIntegerField PositiveIntegerField/PositiveSmallI
BinaryField ntegerField
BooleanField TextField
CharField TimeField
DateField URLField
DateField(auto_now=False, auto_now_a UUIDField
dd=False, **options)
DateTimeField
DecimalField
DurationField
EmailField
FileField
Null
Models.CharField(max_length=100,null=True)
Blank
models.CharField(max_length=100, blank=True, null=True)
Choices
Default
Help_text
Primary_key
unique
Relationships
Many to One Relationship
django.db.models.ForeignKey
Many to Many Relationship
django.db.models.ManyToManyField
MODEL - METHODS
Custom methods on a model to do row level functionality.
MODEL – MANAGERS
Managers are intended to do TABLE-WIDE operations.
MODEL – INHERITANCE
AGGREGATION
Retrieve objects that are summerise by collection of objects.
Aggregate()
Annoted(num_books=Count(‘Book’))
Count(‘field value’)
Avg(‘price’)
Combining multiple annoted with and without distant.
Exact/iexact
Contains/icontains
In
id__in=[1, 3, 4] equivlent SELECT ... WHERE id IN (1, 3, 4);
Gt/gte/lt/lte
Startswith/istartswith
headline__startswith='Lennon‘ equivlent to SELECT ... WHERE headline LIKE 'Lennon%';
Endswith/iendswith
range
Date/year/month/day/quarter/time/hour/minute/second
isnull
Regex/iregex
How Django knows to UPDATE vs. INSERT
Updating attributes based on existing fields
Field CHOICE details get_FOO_display
Field date object get_next_by_FOO/get_previous_by_FOO
Queryset : iteration/slicing/reverse/annotate/exclude/filter/values/dates
A database query operations are provided to django model.
It is an interface that interacs with database.
Default is django.db.models.Manager
Using Managers.raw()
Manager.raw(raw_query, params=N
one, translations=None)
This method takes a raw SQL query
, executes it and return
django.db.models.query.RawQuery
Set.
Admin login
List_filter
List_display
Filters
Fieldsets
INlineEditing
Search_fields
date_hierarchy
ordering
ROOT_URLCONF
How Django processes a request
django.conf.urls.url()
Django runs through each URL pattern, in order, and stops at the first one that matches the
requested URL
Once one of the regexes matches, Django imports and calls the given view, which is a
simple Python function (or a class-based view). The view gets passed the following
arguments:
An instance of HttpRequest.
If the matched regular expression returned no named groups, then the matches from the
regular expression are provided as positional arguments.
The keyword arguments are made up of any named groups matched by the regular expression,
overridden by any arguments specified in the optional kwargs argument
to django.conf.urls.url().
Introduction to web framework
What is a server, HTTP Request and HTTP Response?
What is a web framework and web application?
Challenges in developing web application.
Django overview and installation
Starting a Django powered project
Django project architecture
Understanding manage.py
Understanding settings.py
Understanding __init__.py and wsgi.py
Understanding urls.py and Python regular expression
Starting your first web application
Django project architectureUnderstanding admin.pyUnderstanding
models.pyUnderstanding views.pyRunning Django development server
Working with Javascript framework
Bootstrap tutorial
Templates
Developing standard web templateTemplate tagsFilters in templatesTemplate API
Django Admin
Activating the Admin interface
Creating super user for Admin site
Using the Admin site
How to use the Admin site
The django.contrib package
Models
The MVC Development Pattern
Defining Models using Python classes
Defining Model data fields
Initializing model using makemigrations
Running model initialization using migrate
Registering models in settings.py
Registering models with Admin site
Views and URLconfs
Understanding the view layer
Requesting a web page via URL
Rendering web page via view function
Render HTTPResponse to templates
Understanding context data and Python dictionary type
Forms
Form basics
GET and POST methods
Form validation
Rendering forms
ModelForm
Working with Static File
Creating static repository
Loading static files
Adding image file to template
Advance Models, Views, Forms and Admin
Understanding model fields in depth
Database function
Model managers
Django ORMClass based viewsFile submission
Making admin more robust
Extending Templates
Creating a template libraryWriting custom template filterWriting custom templates
tagsRegistering the tagsSetting a variable in the contextWriting template loader
Testing in Django
Testing Django
Writing a unit test
Test ClientRequest
FactoryRunning Tests
Deploying web application
Implementing for not for not template
Setting up error and broken link alerts
Deploying Django application on GitHub
Deploying Django application on Amazon Web Services
Relationship: ManyToManyField intermediate model.
Models: META
Models:
Models: Database transactions.
Models: Multiple databases.
Models: Custom Manager With Chainable QuerySets
If more
mail:
[email protected] TARGET company approached you , described about their problem like facing for
their MALL suchthat their offline shopping sales slips as expectations recent
quarters, so they decided to make to develop an online application for increasing
the sales.
Their requirement are: