|
|
<!doctype html> |
|
|
<html lang="en"> |
|
|
|
|
|
<head> |
|
|
<meta charset="utf-8"> |
|
|
|
|
|
<title>Entendendo DJANGO</title> |
|
|
|
|
|
<meta name="description" content="A framework for easily creating beautiful presentations using HTML"> |
|
|
<meta name="author" content="Hakim El Hattab"> |
|
|
|
|
|
<meta name="apple-mobile-web-app-capable" content="yes"> |
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> |
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui"> |
|
|
|
|
|
<link rel="stylesheet" href="reveal.js/css/reveal.css"> |
|
|
<link rel="stylesheet" href="reveal.js/css/theme/solarized.css" id="theme"> |
|
|
|
|
|
<!-- Code syntax highlighting --> |
|
|
<link rel="stylesheet" href="reveal.js/lib/css/zenburn.css"> |
|
|
|
|
|
<!-- Printing and PDF exports --> |
|
|
<script> |
|
|
var link = document.createElement( 'link' ); |
|
|
link.rel = 'stylesheet'; |
|
|
link.type = 'text/css'; |
|
|
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'reveal.js/css/print/paper.css'; |
|
|
document.getElementsByTagName( 'head' )[0].appendChild( link ); |
|
|
</script> |
|
|
|
|
|
<!--[if lt IE 9]> |
|
|
<script src="lib/js/html5shiv.js"></script> |
|
|
<![endif]--> |
|
|
|
|
|
<!-- personal styles --> |
|
|
<style> |
|
|
.semi-opaque { |
|
|
background-color: rgba(0, 0, 0, 0.7); |
|
|
} |
|
|
|
|
|
img { |
|
|
height: 400px; |
|
|
} |
|
|
</style> |
|
|
</head> |
|
|
|
|
|
<body> |
|
|
<div class="reveal"> |
|
|
<div class="slides"> |
|
|
<section data-backgroun='_images/django-allauth.png'> |
|
|
<p class='semi-opaque'> |
|
|
<h1>Django</h1> |
|
|
<h2>Uma Introdução</h2> |
|
|
</p> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<section> |
|
|
<img src="_images/AYV1X0yv.png" alt="Me" style="float:left;"> |
|
|
|
|
|
<div> |
|
|
<ul> |
|
|
<li>Júlio Biason</li> |
|
|
<li>CWI Software</li> |
|
|
<li>@juliobiason</li> |
|
|
<li>julio.biason@gmail.com</li> |
|
|
</ul> |
|
|
</div> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<img src="_images/meetings.png" alt="Eu consigo detonar com reuniões" styl> |
|
|
</section> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<section> |
|
|
<h2>Projeto</h2> |
|
|
|
|
|
<p>"Projeto" é como Django chama a base do sistema, |
|
|
que não passa de um conjunto de apps.</p> |
|
|
|
|
|
<p>Criado com <code>django-admin startproject [PROJECTNAME] .</code>.</p> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<h2>Projeto: startproject</h2> |
|
|
|
|
|
<pre><code class="hljs" data-trim> |
|
|
project/ |
|
|
├── manage.py |
|
|
└── project |
|
|
├── __init__.py |
|
|
├── settings.py |
|
|
├── urls.py |
|
|
└── wsgi.py |
|
|
</pre></code> |
|
|
|
|
|
<aside class="notes"> |
|
|
startproject cria a estrutura do projeto. |
|
|
manage.py contem a estrutura de execução do projeto |
|
|
project contém a base do projeto. |
|
|
settings são as configuração do projeto. |
|
|
urls define a base das rotas. |
|
|
wsgi serve para a execução por wsgi. |
|
|
</aside> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<h2>Time out: rodando o servidor de desenvolvimento</h2> |
|
|
|
|
|
<pre><code class="hljs" data-trim> |
|
|
$ python manage.py runserver |
|
|
Performing system checks... |
|
|
|
|
|
System check identified no issues (0 silenced). |
|
|
|
|
|
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. |
|
|
Run 'python manage.py migrate' to apply them. |
|
|
|
|
|
October 24, 2016 - 23:04:50 |
|
|
Django version 1.10.2, using settings 'project.settings' |
|
|
Starting development server at http://127.0.0.1:8000/ |
|
|
Quit the server with CONTROL-C. |
|
|
</code></pre> |
|
|
|
|
|
<aside class="notes"> |
|
|
O que diabos aconteceu? |
|
|
primeiro, "runserver" carrega o servidor de desenvolvimento. |
|
|
qualquer alteração em arquivos irá recarregar o serviço. |
|
|
13 migrações não aplicadas; o django já vem com |
|
|
um conjunto de aplicações. |
|
|
</aside> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<pre><code class="hljs" data-trim> |
|
|
$ python manage.py migrate |
|
|
Operations to perform: |
|
|
Apply all migrations: admin, auth, contenttypes, sessions |
|
|
Running migrations: |
|
|
Applying contenttypes.0001_initial... OK |
|
|
Applying auth.0001_initial... OK |
|
|
Applying admin.0001_initial... OK |
|
|
Applying admin.0002_logentry_remove_auto_add... OK |
|
|
Applying contenttypes.0002_remove_content_type_name... OK |
|
|
Applying auth.0002_alter_permission_name_max_length... OK |
|
|
Applying auth.0003_alter_user_email_max_length... OK |
|
|
Applying auth.0004_alter_user_username_opts... OK |
|
|
Applying auth.0005_alter_user_last_login_null... OK |
|
|
Applying auth.0006_require_contenttypes_0002... OK |
|
|
Applying auth.0007_alter_validators_add_error_messages... OK |
|
|
Applying auth.0008_alter_user_username_max_length... OK |
|
|
Applying sessions.0001_initial... OK |
|
|
</code></pre> |
|
|
|
|
|
<aside class="notes"> |
|
|
fazendo o migrate resolve tudo. |
|
|
</aside> |
|
|
</section> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<section> |
|
|
<h2>App</h2> |
|
|
|
|
|
<p> |
|
|
App é como o Django chama as pequenas partes que |
|
|
compõem o sistema. |
|
|
</p> |
|
|
|
|
|
<p> |
|
|
Uma app pode ser entendida como uma tabela, ou um |
|
|
conjunto de tabelas que trabalham em conjunto ou |
|
|
conjunto de funções auxiliares. |
|
|
</p> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<h2>App: startapp</h2> |
|
|
|
|
|
<pre><code class="hljs" data-trim> |
|
|
django-admin startapp customers |
|
|
</code></pre> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<pre><code class="hljs"> |
|
|
project/ |
|
|
├── customers |
|
|
│ ├── admin.py |
|
|
│ ├── apps.py |
|
|
│ ├── __init__.py |
|
|
│ ├── migrations |
|
|
│ │ └── __init__.py |
|
|
│ ├── models.py |
|
|
│ ├── tests.py |
|
|
│ └── views.py |
|
|
├── db.sqlite3 |
|
|
├── manage.py |
|
|
└── project |
|
|
├── __init__.py |
|
|
├── __init__.pyc |
|
|
├── settings.py |
|
|
├── settings.pyc |
|
|
├── urls.py |
|
|
├── urls.pyc |
|
|
└── wsgi.py |
|
|
</code></pre> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<h2>App: models.py</h2> |
|
|
|
|
|
<pre><code class="hljs"> |
|
|
from __future__ import unicode_literals |
|
|
|
|
|
from django.db import models |
|
|
|
|
|
|
|
|
class Customer(models.Model): |
|
|
|
|
|
name = models.CharField(max_length=100) |
|
|
|
|
|
def __str__(self): |
|
|
return self.name |
|
|
</code></pre> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<pre><code class="hljs"> |
|
|
$ python manage.py runserver |
|
|
Performing system checks... |
|
|
|
|
|
System check identified no issues (0 silenced). |
|
|
October 25, 2016 - 21:01:40 |
|
|
Django version 1.10.2, using settings 'project.settings' |
|
|
Starting development server at http://127.0.0.1:8000/ |
|
|
Quit the server with CONTROL-C. |
|
|
</code></pre> |
|
|
|
|
|
<aside class="notes"> |
|
|
Cade os migrations? |
|
|
</aside> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<h2>App: Adicionando ao projeto</h2> |
|
|
|
|
|
<pre><code class="hljs"> |
|
|
INSTALLED_APPS = [ |
|
|
'django.contrib.admin', |
|
|
'django.contrib.auth', |
|
|
'django.contrib.contenttypes', |
|
|
'django.contrib.sessions', |
|
|
'django.contrib.messages', |
|
|
'django.contrib.staticfiles', |
|
|
'customers' |
|
|
] |
|
|
</code></pre> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<pre><code class="hljs"> |
|
|
$ python manage.py makemigrations |
|
|
Migrations for 'customers': |
|
|
customers/migrations/0001_initial.py: |
|
|
- Create model Customer |
|
|
</code></pre> |
|
|
|
|
|
<pre><code class="hljs"> |
|
|
$ python manage.py migrate |
|
|
Operations to perform: |
|
|
Apply all migrations: admin, auth, contenttypes, customers, sessions |
|
|
Running migrations: |
|
|
Applying customers.0001_initial... OK |
|
|
</code></pre> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<h2>App: Admin</h2> |
|
|
|
|
|
<pre><code class="hljs"> |
|
|
from django.contrib import admin |
|
|
|
|
|
from customers.models import Customer |
|
|
|
|
|
|
|
|
class CustomerAdmin(admin.ModelAdmin): |
|
|
pass |
|
|
|
|
|
|
|
|
admin.site.register(Customer, CustomerAdmin) |
|
|
</code></pre> |
|
|
</section> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<section> |
|
|
<h2>Outro App</h2> |
|
|
|
|
|
<pre><code class="hljs"> |
|
|
from __future__ import unicode_literals |
|
|
|
|
|
from django.db import models |
|
|
|
|
|
from customers.models import Customer |
|
|
|
|
|
|
|
|
class Order(models.Model): |
|
|
|
|
|
customer = models.ForeignKey(Customer) |
|
|
date = models.DateField(auto_now_add=True) |
|
|
|
|
|
def __str__(self): |
|
|
return '{name} - {items} item'.format( |
|
|
name=self.customer.name, |
|
|
items=self.item_set.count()) |
|
|
|
|
|
|
|
|
class Item(models.Model): |
|
|
order = models.ForeignKey(Order) |
|
|
item = models.CharField(max_length=30) |
|
|
qtd = models.PositiveIntegerField() |
|
|
price = models.DecimalField(max_digits=8, decimal_places=2) |
|
|
|
|
|
@property |
|
|
def total(self): |
|
|
return self.qtd * self.price |
|
|
</code></pre> |
|
|
</section> |
|
|
|
|
|
<section> |
|
|
<h2>Admin</h2> |
|
|
|
|
|
<pre><code class="hljs"> |
|
|
from django.contrib import admin |
|
|
|
|
|
from orders.models import Order |
|
|
from orders.models import Item |
|
|
|
|
|
|
|
|
class Itemadmin(admin.TabularInline): |
|
|
model = Item |
|
|
|
|
|
|
|
|
class OrderAdmin(admin.ModelAdmin): |
|
|
inlines = [Itemadmin] |
|
|
|
|
|
|
|
|
admin.site.register(Order, OrderAdmin) |
|
|
</code></pre> |
|
|
</section> |
|
|
</section> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
<script src="reveal.js/lib/js/head.min.js"></script> |
|
|
<script src="reveal.js/js/reveal.js"></script> |
|
|
|
|
|
<script> |
|
|
// Full list of configuration options available at: |
|
|
// https://github.com/hakimel/reveal.js#configuration |
|
|
Reveal.initialize({ |
|
|
controls: true, |
|
|
progress: true, |
|
|
history: true, |
|
|
center: true, |
|
|
|
|
|
transition: 'slide', // none/fade/slide/convex/concave/zoom |
|
|
|
|
|
// Optional reveal.js plugins |
|
|
dependencies: [ |
|
|
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } }, |
|
|
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, |
|
|
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, |
|
|
{ src: 'reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.configure({languages: ['python']}); hljs.initHighlightingOnLoad(); } }, |
|
|
{ src: 'reveal.js/plugin/zoom-js/zoom.js', async: true }, |
|
|
{ src: 'reveal.js/plugin/notes/notes.js', async: true } |
|
|
] |
|
|
}); |
|
|
</script> |
|
|
</body> |
|
|
</html>
|
|
|
|