Login

Snippets by baumer1122

Snippet List

Admin Image Widget

A FileField Widget that displays an image instead of a file path if the current file is an image. Could also be used with sorl.thumbnail to generate thumbnail images. **Example** class FileUploadForm(forms.ModelForm): upload = forms.FileField(widget=AdminThumbnailWidget) class Meta: model = FileUpload class FileUploadAdmin(admin.ModelAdmin): form = FileUploadForm admin.site.register(FileUpload, FileUploadAdmin)

  • image
  • newforms-admin
  • widget
  • file
  • nfa
Read More

Creator/updater fields for admin

This ModelAdmin class sets fields for models saved in admin corresponding to the user that created the object and the user that last updated the object. Trivial for the current model, but a little more involved to make it work with inlines. The fields still show up as drop-downs (`select`) in the admin, but I fixed that with a little jQuery: $(function(){ $("select[id*='creator'], select[id*='updater']").each(function(){ var user = $('option:selected', this).text(); $(this).siblings('.add-another').hide(); $(this).hide(); $(this).after(user); }); }); This could easily be subverted, but with trusted users, it makes for a quick and dirty read-only field.

  • admin
  • newforms-admin
Read More

Search Docs with Shortwave

. . For use with [Shortwave](http://shortwaveapp.com/). Add this to your hosted `wave.txt` for a search of the current Django docs.

  • search
  • documentation
  • shortwave
Read More

FormMail Clone

A quickie clone of good old fashion [Formmail.pl](http://www.scriptarchive.com/formmail.html) any form that is a subclass of FormMail will have its conents emailed to all staff members on the site.

  • newforms
  • email
  • formmail
Read More

escapejs block tag

Block tag version of [escapejs](http://www.djangoproject.com/documentation/templates/#escapejs). Handy when using inclusion tags to generate AJAX responses.

  • tag
  • javascript
  • escapejs
Read More

Hierarchical page slugs

This allows for urls in the form of `/grandparent-slug/parent-slug/self-slug/` where the number of parent slugs could be 0 to many. You'll need to make sure that it is your last urlpattern because it is basically a catch-all that would supersede any other urlpatterns. Assumes your page model has these two fields: * `slug = models.SlugField(prepopulate_from=("title",), unique=True)` * `parent = models.ForeignKey("self", blank=True, null=True)`

  • slug
  • url
Read More

Feed Reader Inclusion Tag

This is an inclusion tag that can be used to pull in posts from any feed to a template. It doesn't do any caching, so it may slow down page load times. Depends on [Feedparser](http://www.feedparser.org). Template usage: {% pull_feed 'http://www.djangosnippets.org/feeds/latest/' 3 %}

  • feed
  • rss
  • inclusion-tag
Read More

baumer1122 has posted 8 snippets.