Miguel Cantillana F
<miguel@ewok.cl>
Django es un framework de desarrollo web de código abierto, escrito en el Python. Utiliza el patro de diseño modelo vista controlador (MTV).
Django, el web framework para perfeccionistas
Entendiendo como trabaja Django
docker-compose run web django-admin startproject main .
├── docker-compose.yml
├── Dockerfile
├── main
│ ├── asgi.py
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
└── requirements.txt
version: '3'
services:
web:
image: mcantillana/django_unab:3
ports:
- "8000:8000"
command: python manage.py runserver 0:8000
volumes:
- .:/code
docker-compose run web django-admin startproject main .
├── db.sqlite3
├── docker-compose.yml
├── main
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-36.pyc
│ │ ├── settings.cpython-36.pyc
│ │ ├── urls.cpython-36.pyc
│ │ └── wsgi.cpython-36.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── manage.py
docker-compose run web python manage.py migrate
docker-compose up
docker-compose up -d
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
# Codificación de caracteres
#encoding:utf-8
# Zona horaria
TIME_ZONE = 'America/Santiago'
# Configuración del idioma
LANGUAGE_CODE = 'es-CL'
docker-compose run web python manage.py createsuperuser
Proyecto
App1
App2
App3
App4
docker-compose run web python manage.py startapp blog
├── mysite
| __init__.py
| settings.py
| urls.py
| wsgi.py
├── manage.py
└── blog
├── migrations
| __init__.py
├── __init__.py
├── admin.py
├── models.py
├── tests.py
└── views.py
# se debe registrar el app en setting.py
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
from django.contrib import admin
from .models import Post
admin.site.register(Post)
class OrderItemInline(admin.StackedInline):
model = Order_Item
extra = 0
class OrderProfileAdmin(admin.ModelAdmin):
list_display = ('name', 'paternal_name', 'maternal_name', 'gender', 'email', 'circuit', 'category', 'identification_type', 'identification_country', 'identification_number', 'created', 'updated')
list_filter = ('circuit','category',)
class OrderAdmin(admin.ModelAdmin):
list_display = ('firstname', 'lastname', 'total', 'status', 'created', 'updated','id','uuid')
list_filter = ('status',)
search_fields = ['id','uuid',]
inlines = [OrderItemInline]
class OrderStatusAdmin(admin.ModelAdmin):
list_display = ('name', 'order', 'id')
class OrderDiscountAdmin(admin.ModelAdmin):
list_display = ('name', 'percent', 'code', 'quotas', 'start', 'end', 'created', 'updated', 'race','id')
class OrderDiscountHistoryAdmin(admin.ModelAdmin):
list_display = ('discount', 'ticket', 'order_item', 'date', 'created', 'updated','id')
admin.site.register(Order,OrderAdmin)
admin.site.register(Order_Status,OrderStatusAdmin)
admin.site.register(Order_Profile,OrderProfileAdmin)
admin.site.register(Order_Discount,OrderDiscountAdmin)
admin.site.register(Order_Discount_History,OrderDiscountHistoryAdmin)
python manage.py shell