This file contains hidden or 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
<a href="{{ request.META.HTTP_REFERER }}"> Voltar </a> |
This file contains hidden or 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
/* >>>>>>>>>>>>>>> models.py <<<<<<<<<<<<< */ | |
from django.db import models | |
class MeuModelo(models.Model): | |
estado = models.ForeignKey('Estado') | |
cidade = models.ForeignKey('Cidade') | |
class Pais(models.Model): |
This file contains hidden or 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
if encoding != "utf-8": |
This file contains hidden or 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
Vá no diretório que deseja criar o ambiente virtual | |
cd C:\virtual | |
Crie um ambiente virtual | |
virtualenv --no-site-packages nomedoambiente | |
Ativar o ambiente virtual | |
cd C:\virtual\ambiente1.3\Scripts | |
Comando para ativar o ambiente virtual |
This file contains hidden or 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
file = request.FILES['file'] | |
dialect = csv_mod.Sniffer().sniff(codecs.EncodedFile(file,"utf-8").read(1024)) | |
file.open() | |
csv = csv_mod.DictReader( codecs.EncodedFile(file,"utf-8"), dialect=dialect ) |
This file contains hidden or 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 MyModelAdmin(admin.ModelAdmin): | |
def queryset(self, request): | |
qs = super(MyModelAdmin, self).queryset(request) | |
if request.user.is_superuser: | |
return qs | |
return qs.filter(author=request.user) |
This file contains hidden or 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
# coding: utf-8 | |
#!/usr/bin/env python | |
from django.conf import settings | |
from django.contrib.auth import models as auth_models | |
from django.contrib.auth.management import create_superuser | |
from django.db.models import signals | |
signals.post_syncdb.disconnect( | |
create_superuser, | |
sender=auth_models, |
This file contains hidden or 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 FiltroManifestacoes(forms.Form): | |
dt_inicial = forms.DateTimeField(label=u'Data Inicial',widget=AdminDateWidget(format='%d/%m/%Y'), | |
input_formats='%d/%m/%Y', required=False) | |
dt_final = forms.DateTimeField(label=u'Data Final',widget=AdminDateWidget(format='%d/%m/%Y'), | |
input_formats='%d/%m/%Y', required=False) | |
def __init__(self, *args, **kwargs): | |
super(FiltroManifestacoes, self).__init__(*args, **kwargs) | |
self.fields['dt_inicial'].input_formats = ['%d/%m/%Y'] | |
self.fields['dt_final'].input_formats = ['%d/%m/%Y'] |
This file contains hidden or 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
#user nobody; | |
worker_processes 1; | |
error_log logs/error.log; | |
#error_log logs/error.log notice; | |
#error_log logs/error.log info; | |
pid logs/nginx.pid; | |
events { |
This file contains hidden or 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 ImagemAdmin(AdminImageMixin, MultiUploadAdmin): | |
list_display = ('nome', 'imagemAdmin', 'projeto') | |
list_editable = ('projeto',) | |
def process_uploaded_file(self, uploaded, object, request): | |
# example: | |
projeto_id = request.POST.get('projeto_id', ['']) | |
title = request.POST.get('title', '') or uploaded.name | |
f = FotoProjeto(nome=title, img=uploaded, projeto_id=projeto_id) | |
f.save() |