Skip to content

Instantly share code, notes, and snippets.

@cyphunk
Created May 22, 2014 10:40
Show Gist options
  • Save cyphunk/b574e99d51c958590bcb to your computer and use it in GitHub Desktop.
Save cyphunk/b574e99d51c958590bcb to your computer and use it in GitHub Desktop.

Django Flat

I don't have the nuanced appreciation for constructs that force a workflow upon me. A little more love, a little less abstraction is what i say. Here is how i keep the django app-creep crap out, and keep it all a little more flat. Just add this to each of your model classes:

class Meta:
    app_label = 'website'

What people tell you to do with django is to create a 'site' and then create 'apps' for different elements of that site. So before you even start writing code you have this crap:

mysite/
├── blog
│   ├── __init__.py
│   ├── admin.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── manage.py
├── mysite
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── news
    ├── __init__.py
    ├── admin.py
    ├── models.py
    ├── tests.py
    └── views.py

I'd rather it look like this:

mysite/
├── admin.py
├── manage.py
├── settings.py
├── urls.py
├── views.py
└── wsgi.py

As your progress you can split code out of views.py into views/news.py and views/blog.py.

Steps:

django-admin.py startproject mysite
cd mysite
mv mysite/* .
rm -rf mysite
patch <<EOP
--- a/manage.py
+++ b/manage.py
@@ -6 +6,3 @@ if __name__ == "__main__":
-    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
+    sys.path.append(os.path.abspath(os.path.dirname("../")))
+    
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
EOP

patch <<EOP
--- a/settings.py
+++ b/settings.py
@@ -13 +13 @@ import os
-BASE_DIR = os.path.dirname(os.path.dirname(__file__))
+BASE_DIR = os.path.dirname(__file__)

Now build your models and views.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment