We can use bulk_create for creating multiple objects in one shot.
Here is an example.
Category.objects.bulk_create(
[Category(name="God"),
Category(name="Demi God"),
Category(name="Mortal")]
)Creating an object with a ForeignKey
- Comments.objects.create(author = Users.objects.get(id=1), comment = "so cute")
How to delete objects
Category.objects.filter(id=1).delete()
will delete the pre exisiting object.
Category.objects.all().count()