background preloader

Web Development

Facebook Twitter

How to create a basic blog in Django » Defining your models. 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.

Psycopg – PostgreSQL database adapter for Python — Psycopg v2.4.5 documentation

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.

PostgreSQL + Python. Psycopg Psycopg is the most popular PostgreSQL adapter for the Python programming language.

PostgreSQL + Python

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.

The Django Book: Version 2.0 (English) Writing your first Django app, part 1. Let’s learn by example.

Writing your first Django app, part 1

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. You can tell Django is installed and which version by running the following command: $ python -c "import django; print(django.get_version())" If Django is installed, you should see the version of your installation. The Web framework for perfectionists with deadlines.