highlight text
How to use: {% load highlight %} {{ text|highlight:'word' }}
- text
- highlighting
- highlight
How to use: {% load highlight %} {{ text|highlight:'word' }}
Custom model field to support two ways encryption. The key is provided in the app settings.py file. It should be at least 32 chars. ** usage ** Assuming that you placed the new code into fields.py from app.fields import EncyptedField class Account(models.Model): password = EncryptedField()
Start simple SMTP server on localhost:25 and print to standard output all email headers and the email body. Useful for debugging outgoing mail without configuring SMTP daemon in development enviroment.
Disable editing adding and deleting inline models in django admin on editing parent model
A very simple way of automatically loading data on model creation. As I am using South I wanted an automatic way of loading initial data only when a new model is create during a migration. Django provides almost everything out of the box by providing the *post_syncdb* signal (triggered also by South migrate command) and the *loaddata* command. The code will simply look for a an existing fixture named `<model>_initial.*` and invoke the *loaddata* command to try to load it Note: beware *post_syncdb* signal is deprecated since version 1.7: it has been replaced by *post_migrate*.
See http://stackoverflow.com/questions/927729/how-to-override-the-verbose-name-of-a-superclass-model-field-in-django/24475838#24475838
Based on [#2369](https://djangosnippets.org/snippets/2369/) Save the snippet as actions.py within your django app, and then add an action on any model you want in it's ModelAdmin definition. Example usage: from actions import export_as_csv_action class YourModelAdmin(admin.ModelAdmin): list_display = (...) list_filter = [...] actions = [export_as_csv_action("CSV Export", fields=[...])]
When you use Virtualfish, the virtualenv wrapper for the fish shell, you can add hooks for whenever the virtualenv is activated. This little snippet sets some important environment variables and adds the manage.py command with autocompletion so that you won't ever need to write "python ./manage.py help" ever again, but only "manage <TAB>". For this to work you need to source or paste this code in your ~/.config/fish/config.fish
Basic Authentication mixin for Django. Use in your class based views.
**Designed to hold a list of pages and page ranges for a book/magazine index.** A custom model field (and accompanying form field) that saves comma-separated pages and page ranges in human-readable string form. Includes some clean-up code, so that you can add a new page or range at the end of an existing entry, and it will put it in numeric order and combine runs into ranges. So this: 4-33, 43, 45, 60-65, 44, 59 becomes the tidy 4-33, 43-45, 59-65 **NOTE:** If you comment out the raising of the `ValidationError` in the form field's validate() method, it will actually clean up any extraneous characters for you (which could be dangerous, but for me is usually what I want), so even this horrible mess: ;4-33, 46a fads i44 ,p45o gets cleaned to 4-33, 44-46 *This is the first custom field I've ever written for Django, so may be a little rough but seems to work fine.
jQuery code for making custom list on Admin page in DateTime widget. Create new js file in your static folder with this code. To use add custom js to Admin page like this: class NiceAdmin(admin.ModelAdmin): class Media: js = ('js/adminNice.js',) This code will change **all** DateTime widgets on selected page.
A simple way to force SSL on all pages. It's very simple at this point - the only issue I can see right now and I will address this later is if someone sends http:// in another portion of your url.
This defines a new template tag that lets you print your rendered templates (or partial templates) in html that has been prettified by beautiful soup. It is dependent on the beautiful soup library (bs4). Not recommended for production but it is helpful for development and serving readable html. {% load whatever_template_file %}' <body> {% pretty %} <h1>Hello, world.</h1> {% endpretty %} </body>
Your MEDIA_ROOT directories are a mess? FileField save on "upload_to" directories with old/strange/temporary names decided "on the fly" and never fixed down? SmartFolderFileField is the solution! "upload_to" directory depends only on: app, model and field names. No mess, no ambiguities Obviously, in case you need a real callable for a dynamic directory name: please use it! and leave apart FixedFolderFileField Sample: from django.db import models from utilities_app.models import SmartFolderFileField class SampleModel(models.Model): sample_char_field = models.CharField(max_length=50) sample_file_field = SmartFolderFileField()
This snippet will change the field to include the placeholder in the field using the help_text attribute from the model or the form
3109 snippets posted so far.