Snippet List
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
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.
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)`
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 %}
baumer1122 has posted 8 snippets.