Skip to content

Instantly share code, notes, and snippets.

View gladson's full-sized avatar
😎
Vá lutar pelo que você acredita.

Gladson gladson

😎
Vá lutar pelo que você acredita.
View GitHub Profile
class NameAnyModelAdmin(admin.ModelAdmin):
fields = ('field1', ('field2', 'field_checkbox'),)
list_display = ('field1', 'field2', 'field_checkbox',)
search_fields = ('field1',)
actions = ['field_checkbox_action']
def field_checkbox_action(self, request, queryset):
for obj in queryset:
if obj.field_checkbox == False:
@gladson
gladson / forms.py
Last active December 17, 2015 19:09
Add parâmetro no forms | ul_attrs
from django import forms
from .widgets import MyCheckboxSelectMultiple
class Form(forms.Form):
ability = forms.ChoiceField(
widget= MyCheckboxSelectMultiple(ul_attrs={"class":"fancybox"}),
choices = SKILLS,
required=False
)

Project Name

TODO: Write a project description

Installation

TODO: Describe the installation process

Usage

$ python -V
Python 2.6.6
$ curl -kL https://raw.github.com/utahta/pythonbrew/master/pythonbrew-install | bash
$ . $HOME/.pythonbrew/etc/bashrc
$ pythonbrew install 2.7.3
$ pythonbrew switch 2.7.3
Switched to Python-2.7.3
$ python -V
Python 2.7.3
{% load core_utils %}
<ul id="tags" class="nav nav-tabs nav-stacked">
{% for tag in tags %}
{% if tag_full_list|list_count:tag %}
<li>
<a href="{% url "post:posts-tagged-related" tag.slug %}">
{{ tag.name }} <span class="label label-info">{{ tag_full_list|list_count:tag }}</span>
</a>
</li>
@gladson
gladson / models.py
Created March 23, 2013 16:45
Slug - Signals - Django
# -*- coding: utf-8 -*-
from django.db import models
from django.db.models import signals
from signals import create_slug
class Category(models.Model):
name = models.CharField(u'nome', max_length=100)
slug = models.SlugField(max_length=150, editable=False)
from django.template.defaultfilters import slugify
class AutoSlugMixin(object):
"""
Automatically set slug to slugified version of the name if left empty.
Use this as follows::
class MyModel(AutoSlugMixin, models.Model):
def save(self):
super(MyModel, self).save()
@gladson
gladson / Error?
Created March 20, 2013 06:58
South - django.db.utils.DatabaseError: table "myapp_tablename" already exists
I am trying to get started with South.
I had an existing database.
I added South (syncdb, schemamigration --initial).
I updated models.py to add a field.
I ran ./manage.py schemamigration myapp --auto
# coding: utf-8
u"""
Redimensionamento proporcional de imagem, com base na altura, feito com um simples cálculo de proporção.
Ex:
+------+ 10 15 (altura desejada para a nova imagem)
| | -- x --
| 10x5 | 5 x (largura proporcional a nova altura)
| |
+------+ (10 x x) = (5 x 15)
10x = 75