Django Model Example: Create New Database Entry
Assuming you have a Django model called 'Person' with fields 'name', 'age', and 'email', here is an example of creating a new entry to the database:
from myapp.models import Person
# create a new Person object
new_person = Person(name='John', age=25, email='john@example.com')
# save the object to the database
new_person.save()
Alternatively, you can create and save the object in one line:
Person.objects.create(name='John', age=25, email='john@example.com')
原文地址: https://www.cveoy.top/t/topic/mXUK 著作权归作者所有。请勿转载和采集!