This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALSO SEE THIS: http://eddychan.com/post/18484749431/minimum-viable-ops-deploying-your-first-django-app-to | |
AND THIS: http://bitnami.com/stack/django | |
These are my notes on how to quickly setup a python, virtualenv (use virtualenv-burrito FTW), and django. | |
Setup an EC-2 instance: | |
======================= | |
Use the quick launch wizard: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I have this framed out and working but I wanted to post this question to see how more experienced Django developers would approach this problem. So to use a simple domain | |
that everyone can understand, I will frame this as a simple reporting page on a web site where an investor wants to view different classes of assets (stocks, bonds, cds, | |
etc). I only show three instrument types but like any project it could grow to many more over the project life cycle. | |
Given the following models . . . | |
class Investor(models.Model): | |
first = models.CharField() | |
blah = models.CharField() | |
blan = models.CharField() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find: ^\n <- select the far left button that toggles regex [.*] | |
replace: <p>\n | |
tags: Sublime Text 2, find blank lines, replace blank lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##Clone or Copy a virtualenv## | |
The virtualenvwrapper documentation declares that its feature set includes "Wrappers for managing your virtual environments (create, delete, copy)." But I could not find the copy command anywhere. After fruitless for the command I figred that well designed software usually has a predictable answer: | |
$cpvirtualenv Env1 Env2 | |
So that's the ticket. Where Env1 is your existing venv and Env2 is the new one you wish to start. So I riff off of Patrick Altman's handy [setup instructions] for new Django projects to create a local stub (where I have swapped in the dev release of Django 1.5) and add utilities like South. Starting new projects is now as simple as . . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a contrived example that illustrates my problem. I want to subclass a base class (PersonBase) | |
into several different descendant classes. Each person type can have multiple emails and phone numbers | |
The email and phone class should have a 1..n relationship to all the different people subclasses. | |
I thought could structure this as follows, but the FK cannot be created on the abstract base class. What | |
is the best practice for solving this situation . . . instantiate that base model instead of making it | |
abstract? Or try to implement GenericForeignKeys, or do they introduce more problems than they solve? | |
Here's the problem in pseudocode . . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This gist pertains to a Bad Request(400) error when trying to access an EC2 instance running django . . . | |
I set up an EC2 server, installed django, started runserver and tested. The result was | |
Bad Request (400) | |
When using Django 1.5 and higher, if you specify DEBUG=False in the settings.py file, you must also specify ALLOWED_HOSTS | |
or you will recieve a "Bad Request (400)" error message when attempting to retrieve a page. | |
On an Amazone EC2 instance, if you are ***testing*** with the public DNS, then you should include the public DNS as one of the allowed hosts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This utility addresses the InegrityError that occurs when you try to add a new record to | |
(probably a recently ported) postgres database while using Django, here's more . . . | |
duplicate key value violates unique constraint "<app>_<table>_pkey" | |
DETAIL: Key (id)=(2) already exists. | |
The problem here is that the Postgres sequence generators are out of sync with your data. | |
Here's a good overview: http://www.vlent.nl/weblog/2011/05/06/integrityerror-duplicate-key-value-violates-unique-constraint/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This piece of middleware grabs onto the tail end of process_response hook | |
and allows for redirects to be applied using regex matches. | |
Use Case: A legacy website with many old urls will have accumulated SEO mojo based | |
on external links. When the site is converted to a new fromat (say, drops the cruft like '.html') | |
or goes from abbreviated forms /art/id/t/234234 to /article/2014/january/technology/get-a-better-job | |
the old urls are at risk of breakage and could lose SEO mojo unless preserved | |
Best preservation comes from redirecting old content to new, which is easily accomplished |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What are the "rules" or guidelines for using ' vs " in Elixir? | |
iex> l1 =['test'] | |
['test'] | |
iex> l2 = ['test'] | |
['test'] | |
iex> l1 == l2 | |
true | |
iex> l3 = ["test"] | |
["test"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyPlug do | |
import Plug.Connection | |
def init(options) do | |
# initialize options | |
options | |
end | |
def call(conn, _opts) do |
OlderNewer