On Github gtsalles / django-must-have
Gustavo Carvalho - gtsalles.com.br
Data Migrations
Objetivo: £2,500
Adquirido: £17,952
[settings] KEY = A-RANDOM-SECRET-KEY DEBUG = True DB_HOST = localhost DB_USER = root DB_PWD = MY-DATABASE-PASSWORD DB_PORT = 3306settings.py
from decouple import config SECRET_KEY = config('KEY') DEBUG = config('DEBUG', cast=bool) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': config('DB_NAME'), 'USER': config('DB_USER'), 'PASSWORD': config('DB_PWD', default=''), } }
CRISPY_TEMPLATE_PACK = 'template'
from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit class MeuForm(forms.ModelForm): ... def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.form_action = '/url/form/' self.helper.form_method = 'GET' self.helper.layout = Layout( Fieldset(None, 'nome', 'sexo', 'estado_civil', css_class='span3'), Fieldset(None, 'empregado', 'cnh', 'carro', css_class='span3'), Fieldset(None, 'formacao', css_class='span2'), Fieldset(None, 'categoria', css_class='span2'), Fieldset(None, 'idiomas', css_class='span2'), ButtonHolder( Submit('submit', 'Submit', css_class='button white') ) ) super(MeuForm, self).__init__(*args, **kwargs)
{% load crispy_forms_tags %} {% crispy filter_form %}
{% load widget_tweaks %} {% render_field form.field_name class="classe1 classe2" placeholder="a nice placeholder" %} {% render_field form.title class+="css_class_1 css_class_2" %} {{ form.text|attr:"rows:20"|attr:"cols:20"|attr:"title:Hello, world!" }}
from django.db import models from taggit.managers import TaggableManager class Comida(models.Model): # ... outros campos tags = TaggableManager()
>>> maca = Comida.objects.create(name="maca") >>> maca.tags.add("vermelha", "verde", "deliciosa") >>> maca.tags.all() [Tag: verde, Tag: verde, Tag: deliciosa] >>> maca.tags.remove("verde") >>> maca.tags.all() [Tag: verde, Tag: deliciosa] >>> Comida.objects.filter(tags__name__in=["vermelha"]) [Comida: maca, Comida: morango]
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP TEMPLATE_CONTEXT_PROCESSORS = TCP + ( 'django.core.context_processors.request', )
import reversion reversion.register(YourModel)
import reversion class YourModelAdmin(reversion.VersionAdmin): pass admin.site.register(YourModel, YourModelAdmin)
STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', # other finders.. 'compressor.finders.CompressorFinder', )
{% load compress %} {% compress css %} < link rel="stylesheet" href="css/one.css" type="text/css" charset="utf-8"> < style type="text/css">p { border:5px solid green;}< /style> < link rel="stylesheet" href="css/two.css" type="text/css" charset="utf-8"> {% endcompress %}
< link rel="stylesheet" href="CACHE/css/fb7a124.css" type="text/css" charset="utf-8">