This management command is run like this: `./manage.py -a someapp filename.cfg`
it looks in `someapp`'s directory for a file called `/config/filename.cfg` with the format explained in the help text, and creates the model instances described in the config file.
It uses the configobj module.
this would be an example config file:
[project.Profile]
[[fields]]
receive_notifications = False
[[children]]
[[[auth.User]]]
[[[[fields]]]]
username = AnnonymousUser
password = ! # set unusable password. There's no way yet to hash and set a given password
email = [email protected]
This tag is equivalent to {% cycle %} but resets when we exit the
containing loop.
See Django ticket "Cycle tag should reset after it steps out of scope"
[https://code.djangoproject.com/ticket/5908](https://code.djangoproject.com/ticket/5908)
This code is a lightly modified version of Simon Litchfield's
attachment on that ticket.
You have pagination for some blog. At the bottom of the page you have space for seven page links. This module tries to always fill out those slots. It handles the corner cases for first page and last page etc.
The logic for this is complex and sadly the Django pagination module does not deal with this. Also, it's a hell to implement this in Django templates. Believe me.
See pydoc for detailed documentation. Running tests was done with `doctest`.
This decorator will memoize the results of instance methods, similar to `django.util.functional.memoize`, but automatically creates a cache attached to the object (and therefore shares the life span of the object) rather than requiring you to provide your own. Note this is intended for instance methods only, though it may work in some cases with functions and class methods with at least one argument.
This is useful for memozing results of model methods for the life of a request. For example:
class MyModel(models.Model):
#Fields here
@auto_memoize
def some_calculation(self):
#some calculation here
return result
This snippet loads data from JSON files into a MongoDB database.
The code is related with the other snippet [MongoDB data dump](http://djangosnippets.org/snippets/2872/).
To get it working, just create a ``MONGODB_NAME`` variable in settings, holding the name of your Mongo database. This can be edited to fit more your needs. The snippet requires ``Pymongo``, since it uses its bson module and the ``MongoClient``.
This Django management command just dumps data from a given MongoDB collection into a JSON file.
To get it working, just create a ``MONGODB_NAME`` variable in settings, holding the name of your Mongo database. This can be edited to fit more your needs. The snippet requires Pymongo, since it uses its ``bson`` module and the ``MongoClient``.
Django templatetag wraps everything between ``{% linkif %}`` and ``{% endlinkif %}`` inside a ``link`` if ``link`` is not False.
Sample usage::
{% linkif "http://example.com" %}link{% endlinkif %}
{% linkif object.url %}link only if object has an url{% endlinkif %}
Adds drag-and-drop ordering of rows in the admin list view for Grappelli. This is a updated version of Snippet [#2306](http://djangosnippets.org/snippets/2306/) that works with the current version of Grappelli.
The model needs to have a field holding the position and that field has to be made list_editable in the ModelAdmin. The changes of the ordering are applied after clicking 'Save'.
Sample usage for using decorator
`@json_response(ajax_required=True, login_required=True)`
`def subscribe(request):`
` return {"status":"success"}`
Converts a function returning dict into json response. Does is_ajax check and user authenticated check if set in flags. When function returns HttpResponse does nothing.
Based on [#2712](../2712/)
"This snippet creates a simple generic export to csv action that you can specify the fields you want exported and the labels used in the header row for each field. It expands on #2020 by using list comprehensions instead of sets so that you also control the order of the fields as well."
The additions here allow you to span foreign keys in the list of field names, and you can also reference callables.