Skip to content

Commit

Permalink
Typoes and spellings
Browse files Browse the repository at this point in the history
  • Loading branch information
shabda committed Dec 19, 2009
1 parent ed975b4 commit 80374e4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion source/contents.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Getting the docs
----------------------
The documents are generated using `Sphinx <http://sphinx.pocoo.org/>`_. The code
is available on `Github <http://github.com/uswaretech/django-design-patterns/tree/master>`_.
The generated Html is available on http://djangodesignpatterns.uswaretech.net/
The generated Html is available on http://uswaretech.com/books/djangodesignpatterns/

License
-------------
Expand Down
14 changes: 7 additions & 7 deletions source/misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ out of settings.py into localsettings.py. In your settings.py, you should do::
try:
from localsettings import *
except ImportError:
print 'localsetting could not be imported'
print 'localsettings could not be imported'
pass #Or raise

This should be at the end of settings.py, so that localsetting.py override
Expand Down Expand Up @@ -41,7 +41,7 @@ the request to output this. Make it as a templatetag.
Import as if your apps are on your project path
----------------------------------------------------
Instead of doing `from project.app.models import ModelClass` do `from app.models
import ModelClass`. Your apps are reusable
import ModelClass`. This makes you apps reusable as they are not tied to a project.

Naming things
-----------------
Expand All @@ -56,12 +56,12 @@ and not::
class Posts(models.Model):
...

Foreign key should use the name of referenced class.::
Foreign key should use the name of the referenced class.::

class Post(models.Model):
user = models.ForeignKey(User)

Queryset should be plural, instances should be singular.::
Querysets should be plural, instances should be singular.::

posts = Post.objects.all()
posts = Post.objects.filter(...)
Expand Down Expand Up @@ -207,8 +207,8 @@ Have you handled all cases?
...

Or it is? What about users created via `manage.py createsuperuser`, with the
above middleware, the default user can not even access the admi site.
above middleware, the default user can not even access the admin site.

Hence handle all scenarios in middleware and context processors. This is one place
where `try: .. except: ..` (bare except) block are acceptable. You do not wnat one
middleare bringing down entire site.
where `try: .. except: ..` (bare except) blocks are acceptable. You do not want one
middleare bringing down the entire site.
7 changes: 5 additions & 2 deletions source/models.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ False in your Model).::
all_objects = models.Manager()
objects = ModelClassApprovedOnlyManager()

If you use multiple managers, the first manager should be the default manager. This is as the first
manager is accesible as `ModelClass._default_manager`, which is used by admin to get all objects.

Hierarchical Relationships
----------------------------
You may want to model hierarchical relationships. The simplest way to do this is::
Expand All @@ -27,9 +30,9 @@ You may want to model hierarchical relationships. The simplest way to do this is
...
parent = models.ForeignKey('ModelClass')

This is called adjacency list model, is very inefficient for large trees. If you
This is called adjacency list model, and is very inefficient for large trees. If your
trees are very shallow you can use this. Otherwise you want to use a more
complex modeling called MPTT. Fortunately, you can just use django-mptt.
efficient but complex modeling called MPTT. Fortunately, you can just use django-mptt.

Singleton classes
-------------------
Expand Down
4 changes: 2 additions & 2 deletions source/templates.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ templates

Projects and apps.
--------------------
There should be one base.html at the project level, and one base.html at each of
the app levels. The app level base.html should extend the project level
There should be one base.html at the project level, and one `base.html` at each of
the app levels. The app level `base.html` should extend the project level
`base.html`.::

{# Eg Project base.html #}
Expand Down
4 changes: 2 additions & 2 deletions source/urls.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Urls
Projects and apps
--------------------

There should be one urls.py at the project level, and one urls.py at each app
level. The project level urls.py should include each of the urls.py under a
There should be one `urls.py` at the project level, and one `urls.py` at each app
level. The project level `urls.py` should include each of the `urls.py` under a
prefix.::

#project urls.py
Expand Down
13 changes: 12 additions & 1 deletion source/views.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ be posted on these objects, which this generic view does not allow.::
Handle GET and POST in same view function
----------------------------------------------

This keeps things grouped logically together. Eg.::

def foo(request):
form = FormClass()
if request.method == 'POST':
#Handle post and form saving etv.
#Redirect etc
#Any more get handling
payload = {'form': form, ...}
return render_to_response(...)


Querysets are chainable and lazy
-----------------------------------
This means that your view can keep on creating querysets and they would be
evaluated onlly when used. Supposed when you have an advanced search view which
evaluated only when used. Suppose you have an advanced search view which
can take multiple criteria all of which are optional.::

def advanced_search(request, criteria1=None, criteria2=None, criteria3=None):
Expand Down
8 changes: 4 additions & 4 deletions source/workflow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ workflow

Use a source control system
-------------------------------
Use SVN, GIT, Hg whavere. But choose one and use it.
Use SVN, GIT, Hg whatever. But choose one and use it.

Use a bug tracking tool.
----------------------------
I recommend `Unfuddle <http://unfuddle.com/>`_, (It has various other niecties).
But others might work for you.
I recommend `Unfuddle <http://unfuddle.com/>`_, (It has various niceties, above a source control and bug tracking tool).
But others might work for you. In particular Trac is free.

Use a schema migration tool
------------------------------
Expand All @@ -18,7 +18,7 @@ south is propbably more popular.

Create various entries in your /etc/hosts mapped to localhost
------------------------------------------------------------------
While development you probably want various users logged in to the site
While development you probably want multiple users logged in to the site
simulataneously. For example, while developing, I have one user logged in the admin, one normal
user using the site. If both try to access the site from localhost, one will be
logged out when other logs in.
Expand Down

0 comments on commit 80374e4

Please sign in to comment.