Django 1.6, MS SQL and schemas – Windswept. Problem, of course There was a specific problem I had to solve, namely, on how to make Ubuntu based Django project and remote MS SQL installation talk to each other.
Obviously, that wasn’t really a problem, the problematic part was accessing legacy database with tables under a non-standard schema. Public knowledge, good or bad? PostgreSQL uses "public" as default schema, MS SQL uses [database]. [dbo] But what do you do when tables are stored under an arbitrary schema? A lot of articles and tutorials say that you can use models.Model meta data to point Django into right direction but what I found out is that: SO suggests that db_tablespace applies only for Oraclethere is a fork of PostgreSQL drivers that supports db_schemaalmost everything else outside regular Django development is a custom solution I wouldn’t want to touch for a long run projects.
How to make it work Install everything necessary to be able to access the database. ODBC driver First, choose a correct driver. Python ODBC connector. Fat Models - A Django Code Organization Strategy. A Warning: Almost all Django code examples will lead you down a path of poor code organization.
If your project becomes long-lived, the code organization learned from Django examples will create non-trivial obstacles. This article will present a rarely seen, alternative code organization strategy that can save you a lot of headaches down the road. The Backstory – Redbeacon Builds Very Fast Product iteration at breakneck speed is part of the Redbeacon identity and history. Most Django projects go through a short period of development and then into maintenance. When you make as many changes to a codebase as rapidly as we have, your biggest enemies become cruft and brittle code. Media.revsys.com/images/django-1.5-cheatsheet.pdf?utm_source=Python+Weekly+Newsletter&utm_campaign=e381776e71-Python_Weekly_Issue_83_April_18_2013&utm_medium=email. Ec2 + FreeBSD + Nginx + uWSGI + django. After seeing Amazon’s Free Tier offering for ec2, I decided to throw together a light-weight django server that I could use as a sandbox.
Also, being the cheap bastard that I am, I wanted to squeeze as much juice out of the free instance that I could. Here’s an easy way to do it: First, sign up for an Amazon AWS account. Then create a micro instance using this FreeBSD 9 AMI (ami-8cce3fe5). After selecting the instance, make sure you configure the firewall to allow access for http & ssh (TCP 80 & 22). Install all of the necessary software by running the commands: Setting up Django and your web server with uWSGI and nginx — uWSGI 1.4 documentation. This tutorial is aimed at the Django user who wants to set up a production web server.
It takes you through the steps required to set up Django so that it works nicely with uWSGI and nginx. It covers all three components, providing a complete stack of web application and server software. Django Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. nginx (pronounced engine-x) is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Some notes about this tutorial¶ Note This is a tutorial. Nginx and uWSGI are good choices for Django deployment, but they are not the only ones, or the ‘official’ ones. Deploying Django with Salt Stack. Django Best Practices — Django Best Practices. Show Navigation Navigation If you are looking to make the jump from beginner to pro, or just trying to sharpen your skills, you'll find Django Best Practices chock full of knowledge.
What Djangonauts Say A great overview of best practices in developing and deploying with Django. Bookmarked. Smashing Magazine If you’re a web developer, you should know about this. Mike Loukides This is close to being a direct channel to my brain. Daniel Greenfeld (pydanny) Table of Contents¶ About the Authors Lincoln Loop is a leading Django development consultancy helping startups to large corporations since 2007. Feedback See a problem? Last updated on Jan 20, 2014. Return to Document Django Best Practices Table of Contents. Persisting Django’s Test Database. Posted on August 27th, 2011 by Chris After running Django unittests, it may sometimes be useful to manually inspect the test database after unittests are complete. I was working on a complicated network model, trying to resolve an elusive bug in a unittest, and in this specific instance, I thought running a manually written SQL query would be a bit more helpful than dealing with Django’s ORM.
Since most people don’t really care about the test database, Django’s unittest framework is understandably hard-coded to destroy it after the tests have ran. Although there’s no simply flag to disable this, after digging around in the code, I found it’s relatively easy enough to change with a couple class method overrides. First, for convenience, I define a PERSIST_TEST_DATABASE = 1 flag in my settings.py. Then, my tests.py takes the general form: Models and Managers — django-mptt 0.5.3 documentation. Setting up a Django model for MPTT Start with a basic subclass of MPTTModel, something like this: from django.db import modelsfrom mptt.models import MPTTModel, TreeForeignKey class Genre(MPTTModel): name = models.CharField(max_length=50, unique=True) parent = TreeForeignKey('self', null=True, blank=True, related_name='children') You must define a parent field which is a ForeignKey to 'self'.
Recommended: use TreeForeignKey. You can call it something different if you want - see Model Options below. Because you’re inheriting from MPTTModel, your model will also have a number of other fields: level, lft, rght, and tree_id. Please note that if you are using multi-inheritance, MPTTModel should usually be the first class to be inherited from: