-
-
Save NimishVerma/6489d6741bada2ec015433e822bf9bc6 to your computer and use it in GitHub Desktop.
This file contains 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
# Instatiate Django and import settings | |
import os | |
#mark django settings module as settings.py | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") | |
#instantiate a web sv for django which is a wsgi | |
from django.core.wsgi import get_wsgi_application | |
application = get_wsgi_application() | |
#import your models schema | |
from MyApp.models import Person | |
#Create Operations here | |
data_dict={'name':'Nimish','age':23,email:'nimishverma@ymail.com'} | |
person = Person(**data_dict) | |
person.save() | |
# Read operation logic | |
person = Person.objects.get() | |
print(f'Hello, I am {person.name}, {person.age} y/o. Reachable at {person.email}') | |
#Prints Hello, I am Nimish, 23 y/o. Reachable at nimishverma@ymail.com |
This file contains 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 os, sys | |
if __name__ == "__main__": | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") | |
from django.core.management import execute_from_command_line | |
execute_from_command_line(sys.argv) |
This file contains 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
# MyApp/models.py | |
from django.db import models | |
class Person(models.Model): | |
name = models.TextField() | |
age = models.IntegerField(min_value=18, max_value=110) | |
email = models.EmailField() |
This file contains 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 os | |
# This defines the base dir for all relative imports for our project, put the file in your root folder so the | |
# base_dir points to the root folder | |
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
# According to your data file, you can change the engine, like mysql, postgresql, mongodb etc make sure your data is | |
# directly placed in the same folder as this file, if it is not, please direct the 'NAME' field to its actual path. | |
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.sqlite3', | |
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | |
} | |
} | |
#Since we only have one app which we use | |
INSTALLED_APPS = ( | |
'MyApp', | |
) | |
# Write a random secret key here | |
SECRET_KEY = '4e&6aw+(5&cg^_!05r(&7_#dghg_pdgopq(yk)xa^bog7j)^*j' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment