Django: Insert row into database

If you only want to quick test your models you can start an interactive shell and execute your code there.

python manage.py shell

The above command starts a python interactive shell initialized with your Django project settings.

Then you can do something like:

from your_app_name.models import Dodavatel
p = Dodavatel(nazov='Petr', dostupnost=1)
p.save()

I do not recommend to use that code directly inside a view. Instead to create an item I would use a class based view like CreateView.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)