March 20, 2009

Little Changes

Its not terribly interesting, but I’ve made a couple of very little changes to the site…

  • I finally updated my install of Django from pre-1.0 to 1.0.2. Feels good! Though really anyone else shouldn’t notice any difference. I’m really starting to look forward to Django 1.1!

  • The tree branches that go all the way down the page on the left side now alternate colors… woo!

  • I’ve made site searching more thorough.

  • I’ve done a bit of re-organizing. I’ve finally gotten rid of the Swag section. I still have the Cinema section. However random reviews of other things (such as tv shows or random stuff) will still happen. Until I can think of a better section for it, they’ll just be regular articles that happen to have ratings.

August 4, 2008

Running Django on (mt)

So, I’ve been running on the (mt) Django beta container for a couple of weeks now. So far its been great. I’ve received some questions about it so I figured I’d write up a few notes on the Django container…

  • You get total control over your app without having to manage an entire server.

  • The level of control vs. stability is perfect. This is my most favorite thing ever.

  • You set up and control your Django project/app with a set of terminal commands that all begin with mtd.

  • Overall, it’s been extremely stable. I’d venture to say it seems more stable than the Rails container I used to use… my app has not crashed once yet.

  • You can run on either the last released version of Django or the latest SVN of Django, and switch back and forth with a couple of mtd commands. You can also just download the SVN yourself if you want to be on a specific revision.

  • Note: if you’re running the container on a current SVN of Django (rev. 8015 or above) you will need to add this line to your settings.py for it to run properly:

    `FORCE_SCRIPT_NAME = ''`

I have to say that (mt) has blown my expectations away as far as hosting is concerned, and the Django container is just a part of that. I’d highly recommend them.

July 28, 2008

Stupid-Simple Django Admin Previews

This requires a general understanding of Django’s generic views. It also requires that you have a model that you want to preview. This model must have some kind of ‘draft’ status that is not shown on your live site, but is saved in the database.

So, lets say you have a model called Article. To add a preview for each article:

  • Add a generic object_detail view to your app’s views.py:

    from django.contrib.admin.views.decorators import staff_member_required
    from django.views.generic.list_detail import object_detail
    from your_app.models import Article
    
    
       @staff_member_required
    def preview(request, object_id):
    return object_detail(request, object_id=object_id,
    queryset=Article.objects.all(),
    template_object_name = 'article', )

    That @staffmemberrequired ensures that only people logged into your admin and designated a staff member for your site can see your article’s preview before it is live. The rest is just a generic object_detail view named ‘preview’.

  • Add a line to your app’s urls.py, above your admin url line:

    url(r'^admin/your_app/article/(?P<object_id>[0-9]+)/preview/$',
    'your_app.views.preview'),
  • You don’t actually have to add a template for the view if your project already has an object_detail template (named article_detail.html in this case). The generic view will grab this same template, and you’ll be able to see exactly what your post will look like on your live site.

  • Lastly, add a template to: /templates/admin/your_app/article/change_form.html. Paste this into that template:

    `{% extends "admin/change_form.html" %} {% load i18n %}
        {% block object-tools %}
        {% if change %}{% if not is_popup %}
          
    {% endif %}{% endif %} {% endblock %}`

The beauty of that ‘View preview’ link is it will only appear on the change form for the appropriate model (in this case, Article) and only once the article has been saved to the database (so you must save it as a draft first).

So after you restart your server, every time you save an article as a draft, you’ll be able to click a button and see exactly what your post will look like to the world, without the world having to see it. :)

July 22, 2008

Django!

Excitement!

I have switched from Rails to Django. Ideally this isn’t too big of a change for you, but it is for me. For the first time ever, I have written my own backend!

For the most part it was simple and incredibly fun. Basically its something I though I’d never be able to do, so I’m way too excited about it. Most things should be about the same. If you find any errors or 404’s, please let me know.

Every few months, I had gone to the Django website, looked around a bit, and chickened out. This last time, though, I started reading about it a bit more. I found some various sites made with Django. Then I read that Mephisto’s template language, Liquid, was based on Django’s built-in template language. That was enough for me to get the book and dive in.

As soon as I did, I totally fell in love. A couple days later and things just started flowing. Next thing I knew, I was a part of the (mt) Django beta and here we are!

I’m sure I’ll be talking more about it soon. With any luck its faster and more fun for all.

Please update your RSS subscriptions to: http://feeds.latherrinserepeat.org/all_articles/. Thanks! :D

Clicky Web Analytics