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
| {% load staticfiles %} | |
| <html> | |
| <head> | |
| <title>{% block title %}{% endblock %}</title> | |
| </head> | |
| <body> | |
| <img src="{% static "images/sitelogo.png" %}" alt="Logo" /> | |
| {% block content %}{% endblock %} | |
| </body> | |
| </html> |
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 Photo(models.Model): | |
| image = ImageField(...) # works with FileField also | |
| def save(self, *args, **kwargs): | |
| # delete old file when replacing by updating the file | |
| try: | |
| this = Photo.objects.get(id=self.id) | |
| if this.image != self.image: | |
| this.image.delete(save=False) |
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
| http://i1.ytimg.com/vi/embed/maxresdefault.jpg |
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
| Exclue arquivos terminados em 'pyc' do diretório altosnoticia | |
| find altosnoticia/ -name '*.pyc' -exec rm {} \; | |
| Ver erros do NGINX | |
| /var/log/nginx/error.log |
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
| from forms import SideBarExampleAdminForm, WidgetsExampleAdminForm | |
| class WidgetsExampleAdmin(admin.ModelAdmin): | |
| form = WidgetsExampleAdminForm | |
| admin_site.register(WidgetsExample, WidgetsExampleAdmin) |
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
| def noticia(request, slugcategoria, slug): | |
| # Trago a noticia | |
| noticia = get_object_or_404(Noticias, categoria_nome__slugcategoria=slugcategoria, slug=slug, publicar=True) | |
| # Trago a relacionada | |
| relacionados = Noticias.objects.filter(categoria_nome=noticia.categoria_nome).exclude(pk=noticia.pk).order_by('-criado_em')[:5] | |
| # Quero trazer as ultimas, menos as relacionadas. Aqui é o erro | |
| ultimas = Noticias.objects.filter(publicar=True).exclude(id=relacionados).order_by('-criado_em')[:5] | |
| return render_to_response('juvenis/noticia.html',locals(),context_instance=RequestContext(request)) |
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 Galeria(models.Model): | |
| publicar = models.BooleanField(default=True) | |
| destaque = models.BooleanField(default=False) | |
| nome = models.CharField(max_length=30) | |
| class Foto(models.Model): | |
| img = ImageField('Imagem do projeto', upload_to=rename_file_and_upload_to) | |
| galeria = models.ForeignKey(Galeria, blank=True, null=True) |
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 BaseNoticia(models.Model): | |
| publicar = models.BooleanField(default=True) | |
| destaque = models.BooleanField(default=False) | |
| titulo = models.CharField(max_length=100, unique=True) | |
| conteudo = models.TextField('Conteúdo') | |
| slug = models.SlugField(max_length=150, blank=True, unique=True) | |
| criado_em = models.DateTimeField(auto_now_add=True) | |
| atualizado_em = models.DateTimeField(auto_now=True) | |
| cliques = models.IntegerField('Cliques', default=0, editable=False) |
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 VideoAdmin(admin.ModelAdmin): | |
| class Media: | |
| js = ('/js/tiny_mce/tiny_mce.js', '/js/textareas.js') | |
| fieldsets = [ | |
| ('Principais', {'fields':(('publicar'),('titulo'),'subtitulo', ('conteudo'),)}), | |
| ('Mídia', {'fields':('url','imagem')}), | |
| ] | |
| list_display = ['titulo', 'cliques'] | |
| list_filter = ['publicar'] | |
| search_fields = ['titulo'] |
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 get_fieldsets(self, request, obj=None): | |
| if obj: | |
| return [(None, {'fields': ('field_c', 'field_b')})] | |
| return [(None, {'fields': ('field_a', 'field_b', 'field_c')})] | |
| def get_form(self, request, obj=None, **kwargs): | |
| if obj: | |
| defaults = {'exclude': ('field_a',)} | |
| else: |