Coder Social home page Coder Social logo

experimentingdjango's Introduction

Notes

create virtusal env

  • pyhton -m virtualenv env
  • to activate .\envs\Scripts\activate

Create project_1

django-admin startproject project_name

Run server

python manage.py runserver

Create an APP

python manage.py startapp music

Model

  • It is blueprint of databse tables

Views

  • 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' where MusicConfig is class name of app
  • after creating models in music app we need to migrate that changes python manage.py makemigrations then python manage.py migrate
  • You can check actual query of above migration using python manage.py sqlmigrate music 0001 where 0001 is like query_id

Using database from command line

  • 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 or a.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')

Create Admin

Go to command prompt and python manage.py createsuperuser

  • here username : admin and pass is daredevil
Adding Tables maintenance feature to admin block
  • goto music\admin.py
  • Import models from .models import Album,Song
  • Register Models admin.site.register(Album)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.