diff --git a/django-full.html b/django-full.html index 6fb34aa..159525e 100644 --- a/django-full.html +++ b/django-full.html @@ -38,6 +38,10 @@ .semi-opaque { background-color: rgba(0, 0, 0, 0.7); } + + img { + height: 400px; + } @@ -51,6 +55,25 @@
++ App é como o Django chama as pequenas partes que + compõem o sistema. +
+ ++ Uma app pode ser entendida como uma tabela, ou um + conjunto de tabelas que trabalham em conjunto ou + conjunto de funções auxiliares. +
+
+django-admin startapp customers
+
+
+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
+
+
+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
+
+
+$ 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.
+
+
+
+
+INSTALLED_APPS = [
+ 'django.contrib.admin',
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ 'customers'
+]
+
+
+$ python manage.py makemigrations
+Migrations for 'customers':
+ customers/migrations/0001_initial.py:
+ - Create model Customer
+
+
+
+$ python manage.py migrate
+Operations to perform:
+ Apply all migrations: admin, auth, contenttypes, customers, sessions
+Running migrations:
+ Applying customers.0001_initial... OK
+
+
+from django.contrib import admin
+
+from customers.models import Customer
+
+
+class CustomerAdmin(admin.ModelAdmin):
+ pass
+
+
+admin.site.register(Customer, CustomerAdmin)
+
+
+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
+
+
+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)
+
+