Skip to content

Instantly share code, notes, and snippets.

@Gpzim98
Gpzim98 / DRF
Last active November 17, 2017 15:35
Django Rest Framework views best practices
# 1 - Ideal DRF View
from rest_framework import status
from rest_framework.decorators import detail_route
from rest_framework.response import Response
import logging
def do_log(e):
logger = logging.getLogger('django')
time = datetime.datetime.now()
@Gpzim98
Gpzim98 / Python
Last active April 26, 2018 10:34
1 - ############ built-in zip function for i, j in zip(list1, list2)
2 - ############ built-in enumerate function for i,j in enumerate(lista) i = indice j = element
3 - ############ accessing a global variable a = 10 def foo(): global a a = 10
4 - ########### range performance
Python 2.7
# T1 - Exceptions
In general keep exceptions in views, not in models.
Put exceptions in models just when very necessary like to make process atomic or multiples tasks,
even in this case think if is not better split the method in multiple methos and treat exception in each method
# T2 - Always try to name the relationships
# T3 - Concentrate business logic into models methods and Managers
# T4 - Always help_text
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2017, 9, 22, 9, 34, 11, 593128)
>>> datetime.datetime.now().timestamp()
1506069255.443273
>>> datetime.datetime.now().timestamp() * 1000000000
1.506069262145749e+18
>>> nano_date = datetime.datetime.now().timestamp() * 1000000000
>>> int(nano_date)
1506069271086237952
@Gpzim98
Gpzim98 / gist:9754566
Created March 25, 2014 03:09
Projeto para ensino e aprendizagem de Django
...Projeto para ensino e aprendizagem de Django
@Gpzim98
Gpzim98 / sql
Created February 28, 2014 11:38
Select * from produtos
join empresa on empresa.codempresa = produtos.codempresa
where empresa.codempresa = :pCodEmpresa