background preloader

Django

Facebook Twitter

Setup a Django VM with Vagrant, VirtualBox, and Chef. If you find this post useful, please consider donating in the form of a If you’ve decided that you want to learn the Django framework, but you don’t know where to begin, you’ve come to the right place.

Setup a Django VM with Vagrant, VirtualBox, and Chef

In this guide we’ll be walking step-by-step through the setup of a Django development VM. By the time we’re done we’ll have used a variety of amazing open-source tools to create a virtual machine designed just for Django development. We’re going to use the following tools in the process: VirtualBox (download link)This is the virtualization software we will use to run our Django virtual machine. Workstation Configuration The beauty of using a development VM is that very few configuration changes are required on the host workstation. . # Create django_guide directory in our home directory mkdir ~/django_guide # Change into the newly created ~/django_guide directory cd ~/django_guide Once we’re in this directory, we’re going to instruct vagrant to “initialize” this directory.

Vagrant up Final Steps. Template range tag. Django Class-Based-View Inspector. Django Screencasts and Tutorials - GoDjango.com. A Case for a OneToMany Relationship in Django - Amir Rachum. There are three types of model relationships that Django provides: many-to-one, many-to-many and one-to-one.

A Case for a OneToMany Relationship in Django - Amir Rachum

In the following post I intend to make a case for adding a one-to-many relationship to this list. Obviously, the immediate opposition to this proposal is that all relationships in Django are provided in a two-way manner (via related_name), so there’s no need for it. Let’s take a look at two reasons why I think this new relationship is called for. The many-to-one relationship that Django provides is ForeignKey.

A foreign key is always declared on the “one” side of the relationship, e.g., if you have a Band model and each Band has several Musician models related to it, then you would put a ForeignKey in the Musician model like so: This way, every musician has a band related to it, and bands may have musicians related to them, but this is the wrong way around! This way – every band has musicians. Let’s toss some more models into the mix. Django REST framework - APIs made easy. Burke-software/django-report-builder. Django-tables2 - An app for creating HTML tables — django-tables2 0.16.0.dev documentation.

Django class-based views with multiple inline formsets. This is just a quick explanation of how to use Django's inline model formsets with generic class-based views.

Django class-based views with multiple inline formsets

Handling model forms is an area where it makes sense to use class-based views but there aren't many examples of how to add inline formsets to the mix. Maxime Haineault has a blog post which helped me a lot when I first tried to do this, but his approach of creating inline formsets in the get_context_data method doesn't work if we need to do any validation spanning multiple forms within a formset. The view class I'm using here follows the structure of the generic CreateView more closely so adding mixins, turning this pattern into a mixin, or upgrading to new versions of Django is less likely to cause unpleasant surprises. I've written and tested this using Django 1.5 but it should work for 1.3 and up. Forms and models Let's say that our site lists recipes, which in essence are just lists of ingredients and lists of instructions for preparing those ingredients.

View Template. Your own mini-Heroku for $5/month. Dokku is a lightweight PaaS solution that let's you essentially have a mini self-hosted Heroku.

Your own mini-Heroku for $5/month

This means you can easily take a web application (Django, Rails, etc.) and deploy it with little to no setup. While Heroku offers scalability and support, it does so at a significant cost ($) beyond a very low volume; if you're planning to deploy lots of small or in-development apps, then you don't necessarily need everything Heroku offers, you just need an easy way to (git) push your apps out there. I'm going to walk through the setup of Dokku and then demonstrate how to deploy a Django app with a PostgreSQL database (however, the instructions can be easily re-applied to other frameworks, like Rails). Initial Dokku Setup We can host Dokku on almost any VM or Dedicated Hosting provider (or even your own machine).

Not doing any advance reading about it's requirements, I first tried to set it up on an existing 32bit VM, and then again an Ubuntu 12.10 64bit VM. Django-extensions/django-extensions. Installation instructions — django-extensions 1.2.5 documentation. Download and installation¶ Pip and easy_install¶

Installation instructions — django-extensions 1.2.5 documentation