Django의 일부 구성

10038 단어
//url.py
import xadmin
from MxShop.settings import MEDIA_ROOT
from django.views.static import serve
from rest_framework.documentation import include_docs_urls

url(r'^xadmin/',xadmin.site.urls),
url(r'^media/(?P.*)$',serve,{"document_root":MEDIA_ROOT}),
url(r'docs/', include_docs_urls(title="  ")),

//settings.py

import sys
sys.path.insert(0,BASE_DIR)
sys.path.insert(0,os.path.join(BASE_DIR,'apps'))
sys.path.insert(0,os.path.join(BASE_DIR,'extra_apps'))

AUTH_USER_MODEL='user.UserProfile' //      ,       

APP   
    'user.apps.UserConfig',
    'trade.apps.TradeConfig',
    'goods.apps.GoodsConfig',
    'user_operation.apps.UserOperationConfig',
    'DjangoUeditor',
    'crispy_forms',
    'django_filters',
    'xadmin',
    'rest_framework',


//   

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': "databaseName",
        'USER': 'ROOT',
        'PASSWORD': "xxxx",
        'HOST': "xxx",
        'OPTIONS': { 'init_command': 'SET default_storage_engine=INNODB;' }
    }
}

//admin    

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = False

//      
LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = False


models.py

from django.contrib.auth.models import AbstractUser
class UserProfile(AbstractUser):
    """
      
    """
    name = models.CharField(max_length=30, null=True, blank=True, verbose_name="  ")

    class Meta:
        verbose_name = "  "
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username  // name    ,    username

   models.py       

from django.db import models
from django.contrib.auth import get_user_model

from goods.models import Goods
User = get_user_model()

class ShoppingCart(models.Model):
    """
       
    """
    user = models.ForeignKey(User, verbose_name="  ",on_delete=models.CASCADE)
  
  class Meta:
  verbose_name = ' '
  verbose_name_plural = verbose_name
  unique_together = ("user", "goods")

  def __str__(self):
  return "%s(%d)".format(self.goods.name, self.nums)
   

좋은 웹페이지 즐겨찾기