Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "ptr" stand for in Django ORM column names?

Tags:

django-orm

With these Django ORM models:

class A(Model):
    pass

class B(A):
    pass

The table for B in the resulting schema contains the field:

"a_ptr_id" integer PRIMARY KEY

Just for the sake of better understanding Django's design choices - It there any rationale documentation that mentions what "ptr" signifies?

My only guess is that it's an abbreviation for "pointer", but that seems pretty dumb since essentially any field with a foreign key constraint conceptually resembles a pointer.

like image 640
Chris Martin Avatar asked Jun 10 '14 04:06

Chris Martin


People also ask

What is ORM model in Django?

ORM stands for Object Relational Mapper. The main goal of ORM is to send data between a database and models in an application. It maps a relation between the database and a model. So, ORM maps object attributes to fields of a table.

What does _() mean in Django?

_ is usually a macro/function from gettext, it means the argument is a localized string.


1 Answers

It does stand for "pointer", but it's only used specifically for model inheritance in order to point to the parent model. Normal FKs only get "_id".

like image 143
Ignacio Vazquez-Abrams Avatar answered Nov 08 '22 16:11

Ignacio Vazquez-Abrams