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
class NomeDoForm(forms.ModelForm): | |
class Meta: | |
model = NomeDoModel | |
def __init__(self, *args, **kwargs): | |
super(NomeDoForm, self).__init__(*args, **kwargs) | |
self.fields['nome_do_campo'].widget.attrs['class'] = 'mceClass' |
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
class MyForm(forms.ModelForm): | |
... | |
def __init__(self, *args, **kwargs): | |
self.competition = kwargs.pop('competition') | |
super(MyForm, self).__init__(*args, **kwargs) | |
def clean(self): | |
""" Use self.competition here """ |
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
... | |
class AdminInscricao(ProjectModelAdmin): | |
list_display = ('email', 'nome', 'inscrito', 'admin_grupos', 'data_de_criacao', ) | |
search_fields = ('email', 'nome') | |
list_filter = ('inscrito', 'grupos') | |
actions = ('subscribe_action', 'unsubscribe_action') | |
def admin_grupos(self, obj): |
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
class ProjectForm(ModelForm) | |
.... | |
def clean_name(self): | |
user = self.cleaned_data['user'] | |
queryset = User.objecs.filter(user.id, active=True) | |
if self.instance and self.instance.user: | |
queryset = queryset.exclude(pk = self.instance.user.pk) | |
if queryset.count(): | |
raise forms.ValidationError(_("This man has been already assign to a partner")) | |
return user |
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
import os, uuid | |
from django.conf import settings | |
from django.db import models | |
from django.utils.encoding import smart_unicode, smart_str | |
class BannerFileField(models.FileField): | |
def pre_save(self, model_instance, add): | |
file = super(BannerFileField, self).pre_save(model_instance, add) | |
if not add: |
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 get_first_object_or_none(queryset): | |
try: | |
return queryset[:1][0] | |
except IndexError: | |
return None |
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
{% for evento in eventos %} | |
{% ifchanged %} | |
<h3>{{ evento.data|date:"%F/%Y" }}</h3> | |
{% endifchanged %} | |
{{ evento }} | |
{% endfor %} |
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.db import connection | |
from agenda.models import Evento | |
Evento.objects.extra( | |
select={ | |
'month': connection.ops.date_extract_sql('month', 'data'), | |
'year': connection.ops.date_extract_sql('year', 'data'), | |
}).values('month', 'year').distinct() |