Skip to content

Instantly share code, notes, and snippets.

@ysinjab
Last active October 19, 2018 12:34
Show Gist options
  • Save ysinjab/489a8057146723675311df0e6b100f61 to your computer and use it in GitHub Desktop.
Save ysinjab/489a8057146723675311df0e6b100f61 to your computer and use it in GitHub Desktop.
# in users app i added this model
class User(models.Model):
name = models.CharField(max_length=10)
# in django shell execute the following
from users.models import *
# the object will hold all the logic
new_user = User(name='Yasser')
# this will execute an INSERT
new_user.save()
new_user.name = 'Yasser 2'
# this will execute an UPDATE
new_user.save()
# for retrieving data we have to use objects property (https://docs.djangoproject.com/en/2.1/topics/db/managers/)
User.objects.first() # <User: User object>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment