Saturday, 2 August 2014

how create a model in django


model is a very important part of any framework now i will describe how create a model in django and how it work. model use for data source a model is connector between controller and database, in django connector between view and database actually django is MTV so view call a function from model module and this function is a table name . this function load respective row from database and give  row array

django create table automatic if you add your table in model then when synchronized then this all table will create in mysql database

ok now start by creating the data model for a user table, Open store/ in your editor and type the following code:

from django.db import models
class User(models.Model):
 name = models.TextField(max_length=200)

 password = models.TextField(max_length=200)

 for use this model, we first need to activate it in our Django project. editing, looking for the INSTALLED_APPS variable, and adding application name ( to it:



now type this command in your terminal

$ python syncdb

now type this command for open your django shell

$ python shell

type this command for test database table fecth

from app.models import *
user1 = user(name='Netai Nayek','','netainayek123')

here a row store in user table

for better reference follow