Django Model Field Names

By: Dusty Arlia
Published on Tuesday, April 8, 2014, 06:32 PM
Last Updated on Tuesday, July 07, 2015 at 10:26 PM
Total Updates: 2

When deciding on a Django model field name, there is only two restrictions:

  1. Don't use a Python keyword (or you'll get a Python syntax error)
  2. Don't use two underscores (_) in a row (due to Django’s query lookup syntax)

Your field name doesn’t necessarily have to match your database column name.

SQL reserved words, such as join, where, or select, are allowed as model field names, because Django escapes all database table names and column names in every underlying SQL query. It uses the quoting syntax of your database engine.

Comments:

Ad:

Ad: