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 import forms | |
class Form1(forms.Form): | |
arquivo = forms.FileField() | |
def ler_conteudo_do_arquivo(self): | |
return self.cleaned_data['arquivo'].read() | |
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.simple import direct_to_template | |
from app1.models import Model1 | |
from app2.models import Model2 | |
def index(request): | |
model1_objects = Model1.objects.all()[:3] | |
try: | |
model2_destaque = Model2.objects.all()[:1][0] | |
except IndexError: |
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
def GetAdminAddURL(self, model_class=None, model_instance=None): | |
# Se passar a classe, utiliza a classe, se passar a instancia | |
# pega a classe dela. | |
if model_class is None: | |
model_class = model_instance.__class__ | |
from django.core import urlresolvers | |
from django.contrib.contenttypes.models import ContentType | |
content_type = ContentType.objects.get_for_model(model_class) | |
return urlresolvers.reverse("admin:%s_%s_add" % (content_type.app_label, | |
content_type.model)) |
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 import forms | |
from fields import DecimalInput | |
class ExampleForm(forms.Form): | |
meu_campo = DeicmalInput() |
NewerOlder