pyhton -m virtualenv env
- to activate
.\envs\Scripts\activate
django-admin startproject project_name
python manage.py runserver
python manage.py startapp music
- It is blueprint of databse tables
- Take request from user and responce to user
###Sync databse with code (Migration)
python manage.py migrate
- Need to add new app in settings.py
'music.apps.MusicConfig'
whereMusicConfig
is class name of app - after creating models in music app we need to migrate that changes
python manage.py makemigrations
thenpython manage.py migrate
- You can check actual query of above migration using
python manage.py sqlmigrate music 0001
where 0001 is like query_id
python manage.py shell
- import Models
from music.models import Song
- create an object
a = Album(artist='Lata M',album_title='Love',genre='Evergreen',album_logo='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTlQha7jRO5bqyFIPl02-UpBHVALKTZpvQXo2FTDkIt3S2DLM0K')
- Save object to database
a.save()
- Print primary key of a
a.id
ora.pk
assigned by default - Update data
a.artist='new artist
- Show all object in table
Album.objects.all()
( Need to create strings method to specify , how to return the result of this commong__str__
function) - Applying Filters :
Album.objects.filter(id=1)
- Using Pattern Search
Album.objects.filter(artist__startswith='Kishor')
Go to command prompt and python manage.py createsuperuser
- here username :
admin
and pass isdaredevil
- goto
music\admin.py
- Import models
from .models import Album,Song
- Register Models
admin.site.register(Album)