1. 程式人生 > >3-5 使用者操作的model設計

3-5 使用者操作的model設計

C:\Users\huang\PycharmProjects\MxShop\apps\user_operation\models.py

from datetime import datetime

from django.db import models
from django.contrib.auth import get_user_model
from goods.models import Goods
# Create your models here.
User = get_user_model()


class UserFav(models.Model):
    """
    使用者收藏
    """
    user = models.ForeignKey(User, verbose_name=u"使用者")
    goods = models.ForeignKey(Goods, verbose_name="商品")
    add_time = models.DateTimeField(default=datetime.now, verbose_name="新增時間")

    class Meta:
        verbose_name = u"使用者收藏"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user.name


class UserLeavingMessage(models.Model):
    """
    使用者留言
    """
    MESSAGE_CHOICES = (
        (1, "留言"),
        (2, "投訴"),
        (3, "詢問"),
        (4, "售後"),
        (5, "求購"),
    )
    user = models.ForeignKey(User, verbose_name=u"使用者")
    message_type = models.IntegerField(default=1, choices=MESSAGE_CHOICES, verbose_name="",
                                       help_text=u"留言型別: 1(留言),2(投訴),3(詢問),4(售後),5(求購)")
    subject = models.CharField(max_length=100,default="", verbose_name="主題")
    message = models.TextField(default="", verbose_name="留言內容", help_text="留言內容")
    file = models.FileField(verbose_name="上傳的檔案", help_text="上傳的檔案")

    add_time = models.DateTimeField(default=datetime.now, verbose_name="新增時間")

    class Meta:
        verbose_name = u"使用者留言"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.subject


class UserAddress(models.Model):
    """
    使用者收貨地址
    """
    user = models.ForeignKey(User, verbose_name=u"使用者")
    district = models.CharField(max_length=100, default="", verbose_name="區域")
    address = models.CharField(max_length=100, default="", verbose_name="詳細地址")
    signer_name = models.CharField(max_length=100, default="", verbose_name="簽收人")
    sinner_mobile = models.CharField(max_length=11, default="", verbose_name="電話")
    add_time = models.DateTimeField(default=datetime.now, verbose_name="新增時間")

    class Meta:
        verbose_name = u"收貨地址"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.address