Two search bookmarklets for Django
I run this site through a Django CMS. I often find myself looking for the most recent pages. Now, by default, the most recently edited pages show up at the top, and of course I can link a URL that specifically orders by when pages were added, but there is no way to limit it just to, say, the pages I’ve created this month. Even when I create only a few pages a month, which is normal, those views will still show, in my case, the hundred most recent pages. I’m not aware of a query parameter that will limit the number of results, nor of a query parameter that will only show within the last x days of a date field.
It is possible to show only a single month, but not to show only the current month. Any such bookmark will be out of date once the next month comes around. A JavaScript bookmarklet, however, can do this:
- javascript:today=new%20Date();recentURL='https://django.localhost/admin/cms/page/?created__month='+(today.getMonth()+1)+'&created__year='+today.getFullYear();window.location=recentURL;
I also find myself going to the main list of pages and then doing a search. A bookmarklet can go directly to the search:
- javascript:searchTerm=window.prompt('Search%20for?');searchURL='https://django.localhost/admin/cms/page/?q='+searchTerm;window.location=searchURL;
This will prompt for the search term and then construct a search URL with that term. It does not specifically encode the term, but I’ve tested it in Safari, Firefox, and Chrome and it works.
More Django
- Converting an existing Django model to Django-MPTT
- Using a SQL database to mimic a filesystem will, eventually, create bottlenecks when it comes to traversing the filesystem. One solution is modified preordered tree traversal, which saves the tree structure in an easily-used manner inside the model.
- Fixing Django’s feed generator without hacking Django
- It looks like it’s going to be a while before the RSS feed generator in Django is going to get fixed, so I looked into subclassing as a way of getting a working guid in my Django RSS feeds.
- ModelForms and FormViews
- This is just a notice because when I did a search, nothing came up. Don’t use ModelForm with FormView, use UpdateView instead.
- Django: fix_ampersands and abbreviations
- The fix_ampersands filter will miss some cases where ampersands need to be replaced.
- Custom managers for Django ForeignKeys
- I’ve got one really annoying model for keywords. There’s one category of keywords that, by default, should not show up when used as a ForeignKey for most models. Key word: most.
- 29 more pages with the topic Django, and other related pages