Browse Source

more info about django and python

master
Julio Biason 8 years ago
parent
commit
d82244ff34
  1. 71
      django.html
  2. 39
      python.html

71
django.html

@ -148,7 +148,7 @@ class Product(models.Model):
"""Product information"""
name = models.CharField(max_length=40)
name = models.CharField('Name', max_length=40)
</code></pre>
</section>
@ -187,6 +187,9 @@ class ProductForm(ModelForm):
class Meta:
model = Product
</code></pre>
<p>O "label" do campo ficará com o valor do primeiro parâmetro
usado no field em ModelForms.</p>
</section>
<section>
@ -323,6 +326,43 @@ urlpatterns = [
<img src="_images/goodgood-but-we-must-go-deeper.jpg" alt="Go deeper"/>
</section>
<section>
<section>
<h2>Índices</h2>
<p>Cada campo pode ser indexado usando a propriedade
<code>db_index</code>.</p>
<pre><code class="hljs">
class Order(models.Model):
"""An order."""
costumer.models.ForeignKey(User, db_index=True)
</code></pre>
</section>
<section>
<h2>Meta</h2>
<p>Models podem ter uma classe de "Meta" com informações adicionais:</p>
<pre><code class="hljs">
class Order(models.Model):
"""An order."""
costumer = models.ForeignKey(User, db_index=True)
date = models.DateTimeField(auto_now=True)
class Meta:
db_table = 'my_orders'
index_together = [
('costumer', 'date')
]
</code></pre>
</section>
<section>
<h2>Relationships</h2>
@ -345,6 +385,35 @@ class Order(models.Model):
</code></pre>
</section>
<section>
<h2>"OneToMany"</h2>
<p>
Não existe relacionamento "one to many" (p.ex., um
pedido tem vários ítens de pedido). Para isso,
usa-se o <code>ForeignKey</code> na parte "many".
</p>
<pre><code class="hljs">
class Order(models.Model):
"""An order."""
costumer = models.ForeignKey(Users)
class OrderItem(models.Model):
"""An item of an order."""
order = models.ForeignKey(Order))metro
product = models.ForeignKey(Product)
quantity = models.PositiveIntegerField()
</code></pre>
</section>
</section>
<section>
<h2>Inserts</h2>

39
python.html

@ -266,7 +266,12 @@ Python 2.7.5 (default, Jun 25 2014, 10:19:55)
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt;
</code></pre></p>
</code></pre>
<p class="fragment">
Python 2 (todas as versões), deixarão de ser
suportadas em 2020!
</p>
</section>
<section>
@ -423,12 +428,6 @@ set(['a'])
<p><small>(... que é o nome bonito para coisas tipo <code>if</code>, <code>for</code>...)</small></p>
</section>
<section>
<p>Antes de mais nada...</p>
<h3 class='fragment'>Blocos</h3>
</section>
<section>
<h3><code>if [condição]</code></h3>
@ -687,6 +686,17 @@ iterável[start:end:step]
4
</code></pre></p>
</section>
<section>
<h3>Funções podem conter funções</h3>
<pre><code class="hljs">
&gt;&gt;&gt; def funcao(a, b):
... def inner(b):
... return b * 2 if b &gt; 0 else b * -2
... return inner(a) + b
</code></pre>
</section>
</section>
<section>
@ -949,10 +959,23 @@ class MockRoboDeLimpeza(RoboDeLimpeza, MockRobo)
<a href='https://www.youtube.com/watch?v=EiOglTERPEo'>Super Considered super!</a>
</p>
</section>
<section>
<h3>Assim como funções, classes podem conter classes:</h3>
<pre><code class="hljs">
&gt;&gt;&gt; class Outer(object):
... class Inner(object):
... def __init__(self):
... self.value = 1
... def __init__(self):
... self.value = Inner()
</code></pre>
</section>
</section>
<section>
<h2>As Esquisitices de Python</h2>
<h2>Mais Esquisitices de Python</h2>
</section>
<section>

Loading…
Cancel
Save