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
app/docs/forms.rst:4: WARNING: autodoc: failed to import module u'app.forms'; the following exception was raised: | |
Traceback (most recent call last): | |
File "path/to/sphinx/ext/autodoc.py", line 326, in import_object | |
__import__(self.modname) | |
File "app/forms.py", line 8, in <module> | |
class MyAppForm(ModelForm): | |
File "path/to/django/forms/models.py", line 206, in __new__ | |
opts.exclude, opts.widgets, formfield_callback) | |
File "path/to/django/forms/models.py", line 160, in fields_for_model | |
formfield = f.formfield(**kwargs) |
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 logging | |
from haystack.fields import CharField # Whatever fields you want ... | |
from myapp.models import MyModel | |
logger = logging.getLogger(__name__) | |
try: | |
# haystack 1.2x | |
from haystack import site | |
from haystack.indexes import SearchIndex |
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 MySuperClass(Model): | |
# some stuff follows ... | |
pass | |
class MySubClass(MySuperClass): | |
# unique fields | |
pass | |
obj = MySuperClass.objects.get(pk=1) |
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 uuid import uuid4 | |
>>> from django.db import models | |
>>> from django.contrib.auth.models import User | |
>>> User.objects.create(username=str(uuid4())) | |
<User: > | |
>>> User.add_to_class('username', models.CharField(max_length=300)) | |
>>> User.objects.create(username=str(uuid4())) | |
Traceback (most recent call last): | |
File "<console>", line 1, in <module> | |
File "/django/db/models/manager.py", line 137, in create |
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
var disable_elements = function(evt) { | |
// `this` is the form being submitted, in the current context ... | |
$(this) | |
.find('input[type="submit"], button, a.button') | |
.addClass('disabled') | |
.attr('readonly', 'readonly') | |
.attr('disabled', 'disabled') | |
.css({opacity: 0.5}); | |
// note: the css and disabled parts may need removing, depending | |
// on needs (ie: the css could be set on the `disabled` class) |
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
$('input[type="checkbox"]').live('change', function(evt) { | |
var $this = $(this); | |
var $parent = $this.parent(); | |
if ($this.attr('checked') === true) { | |
$parent.addClass('selected').removeClass('unselected'); | |
return true; | |
} else { | |
$parent.removeClass('selected').addClass('unselected'); | |
return false; | |
} |
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
var previous_result = ''; | |
// listen to an input ... | |
$('#filter-input').live('keyup', function(evt) { | |
var filtering_by = $(this).val().toLowerCase(); | |
if (previous_result === filtering_by) { | |
return; | |
} | |
previous_result = filtering_by; | |
// eg: labels, list items, whatever. | |
var possibles = $('#nodes-to-filter'); |
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
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.mysql', | |
'OPTIONS':{ | |
"init_command": "SET storage_engine=INNODB, collation_connection='utf8_unicode_ci', sql_mode='TRADITIONAL', NAMES 'utf8';", | |
}, | |
}, | |
} |
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.core.paginator import Paginator | |
class ChunkingPaginator(Paginator): | |
def chunked_objects(self): | |
""" | |
Usage: | |
bigqs = ChunkingPaginator(Model.objects.all(), 100) | |
for obj in bigqs.chunked_objects(): | |
# do something with the obj | |
pass |