Commits

Hector Garcia committed 923f274

Updated INSTALL doc. Added POST_MODEL setting to override and extend default Post model

Comments (0)

Files changed (6)

INSTALL

-Installation
-============
-
-The package is listed in the `Python Package Index`_. You can use your
-favorite package manager like easy_install or pip::
-
-    pip install django_nomadblog
-
-You can alternatively download the source code for the latest release or
-development version here::
-
-    http://bitbucket.org/nabucosound/django-nomadblog/downloads/
-
-.. _Python Package Index: http://pypi.python.org/pypi/django-nomadblog/
-
-Mercurial checkout
-------------------
-
-Install Mercurial_ if you don't have it yet, and clone the repository::
-
-    hg clone http://bitbucket.org/nabucosound/django-nomadblog/
-    
-For the old-school guys, symlink to the folder called ``nomadblog`` inside
-``django-nomadblog`` from somewhere in your PYTHONPATH -- could be the
-system-wide ``site-packages`` python folder, or the path your Virtualenv_
-project is using, if you are using it (which I strongly encourage). And if you
-do and are also using Virtualenvwrapper_ then you can easily ``add2virtualenv``.
-
-.. _Mercurial: http://www.selenic.com/mercurial/
-.. _Virtualenv: http://pypi.python.org/pypi/virtualenv/
-.. _Virtualenvwrapper: http://www.doughellmann.com/projects/virtualenvwrapper/
-
-
-Configuration
-=============
-
-Add ``nomadblog`` to the ``INSTALLED_APPS`` setting of your settings file,
-and ``syncdb`` your database if you need to::
-
-	INSTALLED_APPS = (
-		...
-		'nomadblog',
-	)
-
-Include this two lines of code in your root ``urls.py``::
-
-	# Put it somewhere in the beginning of the file
-	NOMADBLOG_MULTIPLE_BLOGS = getattr(settings, 'NOMADBLOG_MULTIPLE_BLOGS', False)
-	
-	# Add this pattern into your url conf
-	urlpatterns = patterns('',
-		...
-	    (r'^blog/', include('nomadblog.urls')) if not NOMADBLOG_MULTIPLE_BLOGS \
-            else (r'^blogs/(?P<blog_slug>[-\w]+)/', include('nomadblog.urls')),
-	)
-
-You can change the ``blog/`` or ``blogs/`` initial part but do not modify
-``(?P<blog_slug>\w+)``, because it is used by the app to differenciate which
-blog is being accessed, in case multiblog is used.
-
-Setting multiblog
-=================
-
-Define the variable ``NOMADBLOG_MULTIPLE_BLOGS`` in your project settings.py
-as ``True`` if you want a Multiple blog configuration::
-
-    NOMADBLOG_MULTIPLE_BLOGS = True
-
+Installation
+============
+
+The package is listed in the `Python Package Index`_. You can use your
+favorite package manager like easy_install or pip::
+
+    pip install django_nomadblog
+
+You can also download the source code for the latest release or
+development version here::
+
+    http://bitbucket.org/nabucosound/django-nomadblog/downloads/
+
+.. _Python Package Index: http://pypi.python.org/pypi/django-nomadblog/
+
+Mercurial checkout
+------------------
+
+Install Mercurial_ if you don't have it yet, and clone the repository::
+
+    hg clone http://bitbucket.org/nabucosound/django-nomadblog/
+    
+For the old-school guys, symlink to the folder called ``nomadblog`` inside
+``django-nomadblog`` from somewhere in your PYTHONPATH -- could be the
+system-wide ``site-packages`` python folder, or the path your Virtualenv_
+project is using, if you are using it (which I strongly encourage). And if you
+do and are also using Virtualenvwrapper_ then you can easily ``add2virtualenv``.
+
+.. _Mercurial: http://www.selenic.com/mercurial/
+.. _Virtualenv: http://pypi.python.org/pypi/virtualenv/
+.. _Virtualenvwrapper: http://www.doughellmann.com/projects/virtualenvwrapper/
+
+Configuration
+=============
+
+Add ``nomadblog`` to the ``INSTALLED_APPS`` setting of your ``settings.py``::
+
+    INSTALLED_APPS = (
+        ...
+        'nomadblog',
+    )
+
+``django-nomadblog`` comes with migrations for the South_ tool::
+
+    ./manage.py migrate nomadblog
+
+If you don't use migrations (you should!) or use a different way to update
+your database,  use ``syncdb``::
+
+    ./manage.py syncdb
+
+Include this two lines of code in your root ``urls.py``::
+
+    # Put it somewhere in the beginning of the file
+    from django.conf import settings
+    MULTIBLOG = getattr(settings, 'NOMADBLOG_MULTIPLE_BLOGS', False)
+    
+    # Add this pattern into your url conf
+    urlpatterns = patterns('',
+        ...
+        url(r'^blog/', include('nomadblog.urls')) if not MULTIBLOG \
+            else (r'^blogs/(?P<blog_slug>[-\w]+)/', include('nomadblog.urls')),
+    )
+
+You can change the ``blog/`` or ``blogs/`` initial part but do not modify
+``(?P<blog_slug>\w+)``, because it is used by the app to differenciate which
+blog is being accessed, in case multiblog is used.
+
+Settings
+========
+
+Multiblog
+---------
+
+Define the variable ``NOMADBLOG_MULTIPLE_BLOGS`` in your project settings
+as ``True`` if you want a multiple blog configuration::
+
+    NOMADBLOG_MULTIPLE_BLOGS = True
+
+Default Post model
+------------------
+
+By default, ``django-nomadblog`` uses the ``Post`` model, but you can extend it
+with your own one, that will be then used by the app views::
+
+    POST_MODEL = 'yourapp.models.YourExtendedPostModel'
+
+Overrriding templates
+=====================
+
+``django-nomadblog`` uses different templates to list posts, show a post details,
+list categories or list posts by categary. You will want to override these
+templates, to add your layout, design and own stuff. Create a new ``nomadblog``
+template folder where your project can find it and copy the templates found on
+the ``templates/nomadblog`` directory (like ``list_posts.html`` or
+``show_post.html``) or, if you want to be quicker, just copy the entire
+``templates/nomadblog`` folder.
+

nomadblog/migrations/0001_initial.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding model 'Blog'
+        db.create_table('nomadblog_blog', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50, db_index=True)),
+            ('title', self.gf('django.db.models.fields.CharField')(max_length=100)),
+            ('description', self.gf('django.db.models.fields.CharField')(max_length=500)),
+            ('creation_date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
+        ))
+        db.send_create_signal('nomadblog', ['Blog'])
+
+        # Adding model 'BlogUser'
+        db.create_table('nomadblog_bloguser', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
+            ('blog', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['nomadblog.Blog'])),
+        ))
+        db.send_create_signal('nomadblog', ['BlogUser'])
+
+        # Adding model 'Category'
+        db.create_table('nomadblog_category', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length=100)),
+        ))
+        db.send_create_signal('nomadblog', ['Category'])
+
+        # Adding model 'Post'
+        db.create_table('nomadblog_post', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('bloguser', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['nomadblog.BlogUser'])),
+            ('pub_date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
+            ('status', self.gf('django.db.models.fields.IntegerField')(default=0)),
+            ('title', self.gf('django.db.models.fields.CharField')(max_length=300)),
+            ('slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50, db_index=True)),
+            ('category', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['nomadblog.Category'])),
+            ('content', self.gf('django.db.models.fields.TextField')()),
+        ))
+        db.send_create_signal('nomadblog', ['Post'])
+
+
+    def backwards(self, orm):
+        
+        # Deleting model 'Blog'
+        db.delete_table('nomadblog_blog')
+
+        # Deleting model 'BlogUser'
+        db.delete_table('nomadblog_bloguser')
+
+        # Deleting model 'Category'
+        db.delete_table('nomadblog_category')
+
+        # Deleting model 'Post'
+        db.delete_table('nomadblog_post')
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'nomadblog.blog': {
+            'Meta': {'object_name': 'Blog'},
+            'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'users': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'through': "orm['nomadblog.BlogUser']", 'symmetrical': 'False'})
+        },
+        'nomadblog.bloguser': {
+            'Meta': {'object_name': 'BlogUser'},
+            'blog': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['nomadblog.Blog']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
+        },
+        'nomadblog.category': {
+            'Meta': {'object_name': 'Category'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'nomadblog.post': {
+            'Meta': {'object_name': 'Post'},
+            'bloguser': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['nomadblog.BlogUser']"}),
+            'category': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['nomadblog.Category']"}),
+            'content': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'pub_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}),
+            'status': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '300'})
+        }
+    }
+
+    complete_apps = ['nomadblog']

nomadblog/migrations/__init__.py

Empty file added.

nomadblog/urls.py

-from django.conf.urls.defaults import *
+from django.conf.urls.defaults import patterns, url
 
 
 urlpatterns = patterns('nomadblog.views',

nomadblog/views.py

 from django.shortcuts import render_to_response
 from django.template import RequestContext
 from django.shortcuts import get_object_or_404
-from django.contrib.auth.models import User
 from django.conf import settings
 
-from nomadblog.models import Blog, BlogUser, Post, Category
+from nomadblog.models import Blog, BlogUser, Category
 
-multiblog = getattr(settings, 'NOMADBLOG_MULTIPLE_BLOGS', False) 
+multiblog = getattr(settings, 'NOMADBLOG_MULTIPLE_BLOGS', False)
 DEFAULT_STATUS = getattr(settings, 'PUBLIC_STATUS', 0)
+POST_MODEL_IMPORT = getattr(settings, 'POST_MODEL', 'nomadblog.models.Post')
+POST_MODULE, dummy, POST_MODEL_NAME = POST_MODEL_IMPORT.rpartition('.')
+POST_MODEL = getattr(__import__(POST_MODULE, fromlist=[POST_MODULE]), POST_MODEL_NAME)
 
 
 def _get_extra_filters(blog_slug=None, username=None, status=None):
         extra_filters['status'] = status
     return extra_filters
 
-def list_posts_ctxt(request, context=None, model=Post,
+def list_posts_ctxt(request, context=None, model=POST_MODEL,
                     blog_slug=None, username=None, status=None):
     """
     Returns a queryset of post instances. ``model`` param specifies
     post Model to retrieve, either ``Post`` model by default or
-    a subcclass defined by the user. ``blog_slug`` and ``status``
+    a subclass defined by the user. ``blog_slug`` and ``status``
     may be included as extra filters in the query, if passed.
     If no ``context`` is passed, it returns the results in a new
     ``RequestContext`` instead of updating the given one.
     return RequestContext(request, ctxt_dict) if context is None \
         else context.update(ctxt_dict)
 
-def show_post_ctxt(request, category, slug, context=None, model=Post,
+def show_post_ctxt(request, category, slug, context=None, model=POST_MODEL,
                    blog_slug=None, username=None, status=None):
     """
     Returns a post instance with given ``slug``, related to category. ``model``
     return RequestContext(request, ctxt_dict) if context is None \
         else context.update(ctxt_dict)
 
-def list_categories_ctxt(request, context=None, model=Post,
+def list_categories_ctxt(request, context=None, model=POST_MODEL,
                          blog_slug=None, username=None, status=None):
     """
     Returns a list of categories. ``model`` param specifies post Model to
     return RequestContext(request, ctxt_dict) if context is None \
         else context.update(ctxt_dict)
 
-def list_posts_by_category_ctxt(request, category, context=None, model=Post, 
+def list_posts_by_category_ctxt(request, category, context=None, model=POST_MODEL,
                                 blog_slug=None, username=None, status=None):
     """
     Returns a list of posts related to a given category. ``model`` param
 # functions above and get more flexibility, or you can simply use them
 # directly as views into your project.
 
-def list_posts(request, model=Post, blog_slug=None, username=None,
+def list_posts(request, model=POST_MODEL, blog_slug=None, username=None,
                status=DEFAULT_STATUS, order='-pub_date',
                extra_ctxt={}, template='nomadblog/list_posts.html'):
     """
     context.update(extra_ctxt)
     return render_to_response(template, {'multiblog': multiblog}, context)
 
-def show_post(request, category, slug, model=Post, blog_slug=None,
+def show_post(request, category, slug, model=POST_MODEL, blog_slug=None,
               username=None, status=DEFAULT_STATUS,
               extra_ctxt={}, template='nomadblog/show_post.html'):
     """
     context.update(extra_ctxt)
     return render_to_response(template, {'multiblog': multiblog}, context)
 
-def list_categories(request, model=Post, blog_slug=None,
+def list_categories(request, model=POST_MODEL, blog_slug=None,
                     username=None, status=DEFAULT_STATUS,
                     extra_ctxt={}, template='nomadblog/list_categories.html'):
     """
     context.update(extra_ctxt)
     return render_to_response(template, {'multiblog': multiblog}, context)
 
-def list_posts_by_category(request, category, model=Post,
+def list_posts_by_category(request, category, model=POST_MODEL,
                            blog_slug=None, username=None,
                            status=DEFAULT_STATUS, order='-pub_date',
-                           textra_ctxt={},
-                           emplate='nomadblog/list_posts_by_category.html'):
+                           extra_ctxt={},
+                           template='nomadblog/list_posts_by_category.html'):
     """
     By default, a queryset of published Post model
     instances related to the given category and for all users are retrieved.