This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Specific path, only when visiting /accounts/ --> | |
<li class="{% active request "^/accounts/$" %}"><a href="/accounts/">Accounts</a></li> | |
<!-- Glob path, when visiting /blog/* example /blog/, /blog/post1/, /blog/post2/, /blog/post2/subitem/, ... --> | |
<li class="{% active request "^/blog/" %}"><a href="/blog/">Blog</a></li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.auth.models import User | |
class IdentModel(models.Model): | |
user = models.ForeignKey(User) | |
created = models.DateTimeField(auto_now_add=True, editable=False) | |
modified = models.DateTimeField(auto_now=True, editable=False) | |
class Meta: | |
abstract = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from StringIO import StringIO | |
from unittest import TestCase | |
class Foo(object): | |
def hello(self): | |
print 'world' | |
class StdoutTest(TestCase): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from unittest import TestCase | |
from mock import patch | |
def get_age(): | |
return random.randint(15, 99) | |
class AgeTest(TestCase): | |
@patch('patch_example.random.randint') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from middleware import get_current_schema | |
class OtherRouter(object): | |
def db_for_read(self, model, **hints): | |
return get_current_schema() | |
def db_for_write(self, model, **hints): | |
return get_current_schema() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import traceback | |
logger = logging.getLogger('django') | |
class PDFParserManager(object): | |
def run(self): | |
veiculo_list = list() | |
for key, value in enumerate(self.pesquisas): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PreparaLeilaoAdmin(admin.ModelAdmin): | |
model = Leilao | |
extra = 0 | |
can_delete = False | |
form = LeilaoForm | |
def save_model(self, request, obj, form, change): | |
super(PreparaLeilaoAdmin, self).save_model(request, obj, form, change) | |
arquivo = form.cleaned_data.get('arquivo') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic import View | |
class MyView(View): | |
def get_modulos_permitidos(self): | |
""" | |
Escreva o queryset que retorna os módulos | |
permitidos aqui. | |
""" | |
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COLOR_CHOICES = ( | |
('red', 'Red'), | |
('green', 'Green'), | |
('blue', 'Blue'), | |
) | |
class Vehicle(models.Model): | |
year = models.CharField(max_length=4) | |
color = models.CharField(max_length=30, choices = COLOR_CHOICES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import django | |
from myapp import models | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings") | |
django.setup() | |
print models.MyModel.objects.get(pk=1) |
OlderNewer