简体   繁体   English

Django的Manager class中是否有create()方法?

[英]Is there a create() method in the Manager class of Django?

So, I recently started learning Django and found out about the two ways to create obejcts in database using their given API.所以,我最近开始学习 Django 并发现了使用他们给定的 API 在数据库中创建对象的两种方法。 Now, one of the methods is to use the create() methods that is provided by Manager class as follows:现在,其中一种方法是使用 Manager class 提供的 create() 方法,如下所示:

joe = Author.objects.create(name="joe")

Now, objects is the default manager given by Django but I could not find create() method inside the source code.现在,objects 是 Django 给出的默认管理器,但我在源代码中找不到 create() 方法。 Please tell me what am I missing?请告诉我我错过了什么?

create(**kwargs) methods provided by QuerySet . QuerySet提供的create(**kwargs)方法。 That method allows you to create some object immediately and returning the created object itself.该方法允许您立即创建一些 object 并返回创建的 object 本身。 For the detail, you can find the create() method on the Django installation directory.有关详细信息,您可以在 Django 安装目录中找到create()方法。 Exactly in python-path/site-packages/django/db/models/query.py正好在python-path/site-packages/django/db/models/query.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM