How to create a basic blog in Django » Defining your models | djangorocks.com. The model is your database structure. Lets start by opening the models.py file, and start adding some fields. Because I am keeping this simple, I will not be including users at this stage. class Blog(models.Model): title = models.CharField(max_length=100, unique=True) slug = models.SlugField(max_length=100, unique=True) body = models.TextField() posted = models.DateField(db_index=True, auto_now_add=True) category = models.ForeignKey('blog.Category') class Category(models.Model): title = models.CharField(max_length=100, db_index=True) slug = models.SlugField(max_length=100, db_index=True) Now lets see what each part means.
This creates a database table with the name "Blog". Class Blog(models.Model): These are basic fields to be created in your database title = models.CharField(max_length=100, db_index=True) slug = models.SlugField(max_length=100, db_index=True) body = models.TextField() posted = models.DateTimeField(db_index=True, auto_now_add=True) The last field, a little more advanced. Psycopg – PostgreSQL database adapter for Python — Psycopg v2.4.5 documentation. Psycopg is the most popular PostgreSQL database adapter for the Python programming language.
Its main features are the complete implementation of the Python DB API 2.0 specification and the thread safety (several threads can share the same connection). It was designed for heavily multi-threaded applications that create and destroy lots of cursors and make a large number of concurrent INSERTs or UPDATEs.
Psycopg 2 is mostly implemented in C as a libpq wrapper, resulting in being both efficient and secure. It features client-side and server-side cursors, asynchronous communication and notifications, COPY support. Many Python types are supported out-of-the-box and adapted to matching PostgreSQL data types; adaptation can be extended and customized thanks to a flexible objects adaptation system. Psycopg 2 is both Unicode and Python 3 friendly. Contents Indices and tables.
PostgreSQL + Python | Psycopg. Psycopg Psycopg is the most popular PostgreSQL adapter for the Python programming language. At its core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL. Psycopg is released under the terms of the GNU Lesser General Public License, allowing use from both free and proprietary software.
Latest articles Psycopg 2.6.1 released Posted by Daniele Varrazzo on June 16, 2015 Tagged as news, release Psycopg 2.6 and 2.5.5 released Posted by Daniele Varrazzo on February 9, 2015 Psycopg 2.5.4 released Posted by Daniele Varrazzo on August 30, 2014 Tagged as news, release Cancelling PostgreSQL statements from Python Posted by Daniele Varrazzo on July 20, 2014 Tagged as recipe Psycopg 2.5.3 Released Posted by Daniele Varrazzo on May 13, 2014 Tagged as news, release Donate Quick links Tweets JSON adapter, PG 9.2 range support, context manager, error diagnostics, better composite types... only in Psycopg 2.5!
The Django Book: Version 2.0 (English) Writing your first Django app, part 1. Let’s learn by example. Throughout this tutorial, we’ll walk you through the creation of a basic poll application. It’ll consist of two parts: A public site that lets people view polls and vote in them.An admin site that lets you add, change, and delete polls. We’ll assume you have Django installed already. . $ python -c "import django; print(django.get_version())" If Django is installed, you should see the version of your installation. This tutorial is written for Django 1.9 and Python 3.4 or later.
See How to install Django for advice on how to remove older versions of Django and install a newer one. Where to get help: If you’re having trouble going through this tutorial, please post a message to django-users or drop by #django on irc.freenode.net to chat with other Django users who might be able to help. Creating a project¶ If this is your first time using Django, you’ll have to take care of some initial setup. . $ django-admin startproject mysite Note Where should this code live? These files are: Django | The Web framework for perfectionists with deadlines.