This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name":"demo", | |
"version":"0.0.0", | |
"main": "index.js", | |
"dependencies":{ | |
"dep1":"1.2.x", | |
"dep2":"4.2.x" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name":"demo", | |
"version":"0.0.0", | |
"main": "index.js", | |
"dependencies":{ | |
"dep1":"1.2.x", | |
"dep2":"4.2.x" | |
}, | |
"devDependencies":{ | |
"mocha":"1.2.x" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name":"demo", | |
"version":"0.0.0", | |
"main": "index.js", | |
"dependencies":{ | |
"dep1":"1.2.x", | |
"dep2":"4.2.x" | |
}, | |
"devDependencies":{ | |
"mocha":"1.2.x" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name":"demo", | |
"version":"0.0.1" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Django settings for project_name project. | |
""" | |
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.sqlite3', #DATABASE ENGINE PROVIDER | |
'NAME': path.join(PROJECT_ROOT, 'db.sqlite3'), | |
'USER': '', | |
'PASSWORD': '', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
# Each model extends models.Model | |
class Publisher(models.Model): | |
# Simple definition of string field | |
name = models.CharField(max_length=30) | |
address = models.CharField(max_length=50) | |
city = models.CharField(max_length=60) | |
state_province = models.CharField(max_length=30) | |
country = models.CharField(max_length=50) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import django | |
django.setup() | |
#Imports all application models | |
from app.models import * | |
#Initialize new publishers | |
pub1= Publisher(name="O'Reilly Media", address="St. XXX",city= "Sebastopol", state_province="California", country="US", website="http://www.oreilly.com/") | |
pub1.save() | |
pub2= Publisher(name="Apress Media LLC", address="St. XXX",city= "New York City", state_province="New York", country="US", website="https://www.apress.com/") | |
pub2.save() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Use all() method to retrieve all data | |
for pub in Publisher.objects.all(): | |
print(pub.name) | |
#You can access to related tables | |
for book in Book.objects.all(): | |
print(book.title + " - " + book.publisher.name) | |
#You can use filter method to filter data(Keyword WHERE in SQL) | |
filteredBooks = Book.objects.filter(publication_date__year="2002") | |
for b in filteredBooks: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#You can use get() method to retrieve a sigle entry | |
book = Book.objects.get(id=1).title | |
#To update a record simply set an attribute and save the enity | |
book.title = "Title 2" | |
book.save() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#You can use delete() method to remove data | |
book=Book.objects.get(id=1) | |
book.delete() |