Django:모델 클래스

4711 단어 django
구성 데이터베이스
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': '    ',
        'USER': '   ',
        'PASSWORD': '  ',
        'HOST': '      ip,      localhost',
        'PORT': '  ,   3306',
    }
}

모델 정의
        ,        
django             :
               
            html  
            
django             ,            ,                , django           
      
   python      
  django     ,           

속성 정의
     ,      
        django.db.models.fields   ,      ,    django.db.models 
    
  from django.db import models
  models.Field         ,     
            ,      ,       isDelete  ,   BooleanField,    False

필드 유형
AutoField:      ID     IntegerField,     
     ,               
BooleanField:true/false   ,           CheckboxInput
NullBooleanField:  nulltruefalse   
CharField(max_length=    ):   ,         TextInput
TextField:     ,    4000  ,        Textarea
IntegerField:  
DecimalField(max_digits=None, decimal_places=None):  python Decimal           
DecimalField.max_digits:    
DecimalField.decimal_places:         
FloatField: Python float         
DateField[auto_now=False, auto_now_add=False]):  Python datetime.date       
  DateField.auto_now:       ,            ,  “      ”    ,         ,   false
  DateField.auto_now_add:                  ,        ,         ,   false
               TextInput.            JavaScript      ,   “Today”       ,        invalid_date     
auto_now_add, auto_now, and default           ,                  
TimeField:  Python datetime.time       ,   DateField
DateTimeField:  Python datetime.datetime          ,   DateField
FileField:         
ImageField:   FileField        ,           ,        image

필드 옵션
nullTrue,Django     NULLFalse
blank:   True,         ,     Falsenull         ,blank         
db_column:     ,     ,        
db_index:    True,              
default:   
primary_key:   True,               
unique:    True,              

관계
  

       
ForeignKey:   ,          
ManyToManyField:   ,         
OneToOneField:   ,           

     :  .     _set
bookinfo.heroinfo_set

     :  .     

heroinfo.bookinfo

  id:  .  _id
heroinfo.book_id

기본 옵션
        Meta,       
   db_table:       ,        ,        
_
ordering:         ,          ,         
class BookInfo(models.Model):
    ...
    class Meta():
        ordering = ['id']
     -    ,  -    
class BookInfo(models.Model):
    ...
    class Meta():
        ordering = ['-id']
           

좋은 웹페이지 즐겨찾기