Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use auto_created attribute of field in django?

Could you please give me a real example when should I use auto_created attribute in definitions of django model fields? https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.Field.auto_created ? Which kind of problems could be solved by using this flag?

like image 610
pmoniq Avatar asked Sep 13 '25 22:09

pmoniq


2 Answers

Found one example here. http://www.programcreek.com/python/example/74720/django.db.migrations.CreateModel

Here is my wild guess: it is designed for Django primary key implementation, that is, you'd better do not use it unless you are developing Django itself.

fields=[
    ('pony_ptr', models.OneToOneField(
        auto_created=True,
        primary_key=True,
        to_field='id',
        serialize=False,
        to='Pony',
    )),
    "cuteness", models.IntegerField(default=1)),
]
like image 94
Diansheng Avatar answered Sep 17 '25 20:09

Diansheng


You aren't supposed to use it (at least to create fields with such attribute). auto_created=True means that field is created implicitly (id field which is automatically created for your model if you don't specify different primary key).

like image 44
Konstantin Svintsov Avatar answered Sep 17 '25 20:09

Konstantin Svintsov