from django.db import models
from ckeditor.fields import RichTextField

import django.utils.timezone as timezone
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import Group, GroupManager
import datetime
from ckeditor_uploader.fields import RichTextUploadingField
# Create your models here.


# 继承AbstractUser类
class MyUser(AbstractUser):
    user_remark = models.TextField(u'用户备注', max_length=200, blank=True)
    user_phone = models.CharField(u'用户手机', max_length=16, blank=True)
    user_picture = models.ImageField(u'用户头像', upload_to="guser_photo/", default="guser_photo/default.png")
    user_pro = models.CharField(u'用户省', max_length=50, blank=True)
    user_city = models.CharField(u'用户市', max_length=50, blank=True)
    user_area = models.CharField(u'用户区', max_length=50, blank=True)
    limit = models.TextField(u'用户权限', blank=True, null=True)

    class Meta:
        verbose_name = u'用户列表'
        verbose_name_plural = verbose_name
        ordering = ['-date_joined']
        get_latest_by = 'date_joined'



# 设备类型列表：
class Equip_type(models.Model):
    type_id = models.PositiveIntegerField(u'设备类型编号', primary_key=True)
    type_name = models.CharField(u'设备类型名称', max_length=50, blank=True)
    type_add_time = models.DateTimeField(u'设备类型添加时间', default=timezone.now)
    topic_name = models.CharField(u'主题简称', max_length=10, blank=True)

    def __str__(self):
        return self.type_name
    class Meta:
        verbose_name = u"设备类型表"
        verbose_name_plural = verbose_name
        ordering = ['-type_add_time']
        get_latest_by = 'type_add_time'




# 设备列表：
class Equip(models.Model):
    equip_id = models.CharField(u'设备id', max_length=30, primary_key=True)
    equip_user = models.ForeignKey(
        MyUser, blank=True, null=True, verbose_name=u'设备用户')
    equip_type = models.ForeignKey(
        Equip_type, blank=True, null=True, verbose_name=u'设备类型')
    equip_name = models.CharField(u'设备名称', max_length=100, blank=True)
    equip_add_time = models.DateTimeField(u'设备添加时间', default=timezone.now)
    equip_location = models.CharField(u'设备位置', max_length=150, blank=True)
    equip_desc = models.CharField(u'设备状态', max_length=5, blank=True,null=True)
    lng = models.CharField(u'经度', max_length=50, blank=True,null=True)
    lat = models.CharField(u'维度', max_length=50, blank=True,null=True)
    def __str__(self):
        return self.equip_id
    class Meta:
        verbose_name = u"设备列表"
        verbose_name_plural = verbose_name
        ordering = ['-equip_add_time']
        get_latest_by = 'equip_add_time'
        permissions = (
            ("can_see_scd", "Can see scd"),
            ("can_see_cbd", "Can see cbd"),
            ("can_see_ybq", "Can see ybq"),
            ("can_see_qxz", "Can see qxz"),
            ("can_see_jk", "Can see jk"),
            ("can_see_bzy", "Can see bzy"),
        )



# 气象站状态：
# 气象站最新数据记录
class QXZstatus(models.Model):
    equip_id = models.ForeignKey(Equip)
    #auto_now=True:媒体更新状态表时，随之更新上报时间！！！
    upl_time = models.DateTimeField(u'上报时间', auto_now=True)
    qxz_status = models.TextField(u'气象站状态', blank=True, null=True)
    interval = models.CharField(u'设备数据上传时间间隔', max_length=30, blank=True, null=True)
    qxz_picture = models.ImageField(u'气象站图片', upload_to="qxz_photo/", default="qxz_photo/default.png")
    # qxz_picture = models.CharField(u'气象站图片', max_length=200, default="qxz_photo/default.png")

    class Meta:
        verbose_name = u"气象站-状态表"
        verbose_name_plural = verbose_name
        ordering = ['-equip_id__equip_add_time']
        get_latest_by = 'equip_id__equip_add_time'



# 气象站数据记录：
# 气象站全部数据记录
class QXZdata(models.Model):
    equip_id = models.ForeignKey(Equip)
    upl_time = models.DateTimeField(u'数据上传时间', default=timezone.now)
    qxz_data = models.TextField(u'气象站数据', blank=True, null=True)

    class Meta:
        verbose_name = u'气象站-数据表'
        verbose_name_plural = verbose_name
        ordering = ['-upl_time']
        get_latest_by = 'upl_time'


# 值#enum#通道
# 新气象站状态记录：
class QXZstatus_New(models.Model):
    equip_id = models.ForeignKey(Equip)
    upl_time = models.DateTimeField(u'数据上传时间', default=timezone.now)
    e1 = models.CharField(u'通道1', max_length=30, blank=True, null=True)
    e2 = models.CharField(u'通道2', max_length=30, blank=True, null=True)
    e3 = models.CharField(u'通道3', max_length=30, blank=True, null=True)
    e4 = models.CharField(u'通道4', max_length=30, blank=True, null=True)
    e5 = models.CharField(u'通道5', max_length=30, blank=True, null=True)
    e6 = models.CharField(u'通道6', max_length=30, blank=True, null=True)
    e7 = models.CharField(u'通道7', max_length=30, blank=True, null=True)
    e8 = models.CharField(u'通道8', max_length=30, blank=True, null=True)
    e9 = models.CharField(u'通道9', max_length=30, blank=True, null=True)
    e10 = models.CharField(u'通道10', max_length=30, blank=True, null=True)
    e11 = models.CharField(u'通道11', max_length=30, blank=True, null=True)
    e12 = models.CharField(u'通道12', max_length=30, blank=True, null=True)
    e13 = models.CharField(u'通道13', max_length=30, blank=True, null=True)
    e14 = models.CharField(u'通道14', max_length=30, blank=True, null=True)
    interval = models.CharField(u'设备数据上传时间间隔', max_length=30, blank=True, null=True)

    class Meta:
        verbose_name = u'气象站-状态表-新'
        verbose_name_plural = verbose_name
        ordering = ['-upl_time']
        get_latest_by = 'upl_time'



# 新气象站数据记录：
# 新气象站全部数据记录
class QXZdata_New(models.Model):
    equip_id = models.ForeignKey(Equip)
    upl_time = models.DateTimeField(u'数据上传时间', default=timezone.now)
    e1 = models.CharField(u'通道1', max_length=30, blank=True, null=True)
    e2 = models.CharField(u'通道2', max_length=30, blank=True, null=True)
    e3 = models.CharField(u'通道3', max_length=30, blank=True, null=True)
    e4 = models.CharField(u'通道4', max_length=30, blank=True, null=True)
    e5 = models.CharField(u'通道5', max_length=30, blank=True, null=True)
    e6 = models.CharField(u'通道6', max_length=30, blank=True, null=True)
    e7 = models.CharField(u'通道7', max_length=30, blank=True, null=True)
    e8 = models.CharField(u'通道8', max_length=30, blank=True, null=True)
    e9 = models.CharField(u'通道9', max_length=30, blank=True, null=True)
    e10 = models.CharField(u'通道10', max_length=30, blank=True, null=True)
    e11 = models.CharField(u'通道11', max_length=30, blank=True, null=True)
    e12 = models.CharField(u'通道12', max_length=30, blank=True, null=True)
    e13 = models.CharField(u'通道13', max_length=30, blank=True, null=True)
    e14 = models.CharField(u'通道14', max_length=30, blank=True, null=True)

    class Meta:
        verbose_name = u'气象站-数据表-新'
        verbose_name_plural = verbose_name
        ordering = ['-upl_time']
        get_latest_by = 'upl_time'


# 气象站预警列表
class QXZ_Warning(models.Model):
    equip_id = models.ForeignKey(Equip)
    warning_set = models.TextField(u'气象站阈值', blank=True, null=True)
    upl_time = models.DateTimeField(u'数据上传时间', default=timezone.now)
    class Meta:
        verbose_name = u'气象站-预警表'
        verbose_name_plural = verbose_name
        ordering = ['-upl_time']
        get_latest_by = 'upl_time'


# 气象站开关表
class QXZswitchstatus(models.Model):
    equip_id = models.ForeignKey(Equip)
    upl_time = models.DateTimeField(u'数据上传时间', default=timezone.now)
    qxz_switch = models.TextField(u'气象站开关', blank=True, null=True)

    class Meta:
        verbose_name = u'气象站-开关表'
        verbose_name_plural = verbose_name
        ordering = ['-upl_time']
        get_latest_by = 'upl_time'


# 气象站开关配置表
class QXZswitchdata(models.Model):
    equip_id = models.ForeignKey(Equip)
    upl_time = models.DateTimeField(u'数据上传时间', default=timezone.now)
    qxz_switch_data = models.TextField(u'气象站开关名字', blank=True, null=True)

    class Meta:
        verbose_name = u'气象站-开关配置表'
        verbose_name_plural = verbose_name
        ordering = ['-upl_time']
        get_latest_by = 'upl_time'




# 气象站阈值表
class QXZAutoswitch(models.Model):
    equip_id = models.ForeignKey(Equip)
    upl_time = models.DateTimeField(u'数据上传时间', default=timezone.now)
    qxz_auto = models.TextField(u'气象站阈值', blank=True, null=True)

    class Meta:
        verbose_name = u'气象站-阈值表'
        verbose_name_plural = verbose_name
        ordering = ['-upl_time']
        get_latest_by = 'upl_time'

        


# 监控设备token表
class JKdata(models.Model):
    equip_id = models.ForeignKey(Equip, blank=True, null=True, verbose_name=u'设备ID')
    upl_time = models.DateTimeField(u'监控token获取时间', default=timezone.now)
    # 萤石云accesstoken一周过期
    jk_token = models.TextField(u'监控设备所需token', blank=True, null=True)
    jk_type = models.CharField(u'监控设备类型', max_length=10, blank=True, null=True)

    class Meta:
        verbose_name = u'监控-数据表'
        verbose_name_plural = verbose_name
        ordering = ['-upl_time']
        get_latest_by = 'upl_time'



class Article(models.Model):
    '''
    新闻表
    '''
    #标题最大长度255,不能重名
    title = models.CharField(u'文章标题',max_length=255,unique=True)
    #文章简介
    intro = models.CharField(u'文章简介',max_length=255,unique=True)
    #上传文件
    head_img = models.ImageField(upload_to="news_photo/")
    #文章内容(文章内容可能有很多,所以我们就不用"CharField"来写了,我们用TextField,不用规定他多长了,为可扩展长度)
    content = models.TextField(u"内容")
    #文章作者
    author = models.ForeignKey(MyUser,verbose_name="作者")
    #发布日期
    publish_date = models.DateTimeField(default=timezone.now, verbose_name='发布日期', help_text="发布日期")
    #是否隐藏
    hidden = models.BooleanField(default=False,verbose_name="是否隐藏")
    #帖子的优先级
    priority = models.IntegerField(default=1000,verbose_name="优先级")

    # def __unicode__(self):
    #     return "<%s,author:%s>" % (self.title,self.author)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = '新闻文章'
        verbose_name_plural = verbose_name



# 视频数据
class Video_data(models.Model):
    #标题最大长度255,不能重名
    title = models.CharField(u'视频标题',max_length=255,unique=True)
    #视频简介
    intro = models.CharField(u'视频简介',max_length=255,unique=True)
    #上传文件
    video_url = models.FileField(upload_to="videos/", null=True, blank=True, verbose_name="视频内容")
    #视频封面
    video_img = models.ImageField(upload_to="video_photo/", verbose_name="视频封面")
    #视频作者
    author = models.ForeignKey(MyUser,verbose_name="作者")
    #发布日期
    publish_date = models.DateTimeField(default=timezone.now, verbose_name='发布日期', help_text="发布日期")
    #是否隐藏
    hidden = models.BooleanField(default=False,verbose_name="是否隐藏")
    #视频的优先级
    priority = models.IntegerField(default=1000,verbose_name="优先级")

    # def __unicode__(self):
    #     return "<%s,author:%s>" % (self.title,self.author)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = '视频描述'
        verbose_name_plural = verbose_name




class Product(models.Model):
    '''
    产品表
    '''
    #标题最大长度255,不能重名
    title = models.CharField(u'产品标题',max_length=255,unique=True)
    #产品简介
    intro = models.CharField(u'生产企业',max_length=255,unique=True)
    #上传文件
    head_img = models.CharField(u'照片路径', max_length=200, blank=True, null=True)

    content = RichTextUploadingField('正文')
    mobile = models.CharField(u'联系方式', max_length=20, blank=True, null=True)
    #发布用户
    author = models.ForeignKey(MyUser,verbose_name="作者")
    #发布日期
    publish_date = models.DateTimeField(default=timezone.now, verbose_name='发布日期', help_text="发布日期")
    #是否隐藏
    hidden = models.BooleanField(default=False,verbose_name="是否隐藏")
    #帖子的优先级
    priority = models.IntegerField(default=1000,verbose_name="优先级")

    # def __unicode__(self):
    #     return "<%s,author:%s>" % (self.title,self.author)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = '产品简介'
        verbose_name_plural = verbose_name



# 博客模型
class Blog(models.Model):
    title = models.CharField(max_length=254, unique=True)
    # 博客的内容为 RichTextField 对象
    body = RichTextField()

    def __str__(self):
        return self.title



class CKArticle(models.Model):
    author = models.ForeignKey(MyUser,verbose_name=u'作者',blank=True, null=True)
    art_type = models.CharField(u'文章类型',max_length=10, blank=True, null=True)  # 5 新闻资讯  6 视频资讯  7 产品展厅  8 四季采摘  9  民宿导览  10  旅游景点
    writer = models.CharField(u'发布人', max_length=10, blank=True, null=True)
    title = models.CharField(u'标题',max_length=254, null=True, blank=True)
    video_url = models.FileField(upload_to="media/uploads/", null=True, blank=True, verbose_name="视频内容")
    intro = models.CharField(u'简介',max_length=255, null=True, blank=True)
    head_img = models.ImageField(u'封面图片',upload_to="media/uploads/" ,null=True, blank=True)
    content = RichTextUploadingField(u'正文', null=True, blank=True)
    #是否隐藏
    hidden = models.BooleanField(default=False,verbose_name="是否隐藏")
    upl_time = models.DateTimeField(u'数据上传时间', default=timezone.now)
    
    
    def __str__(self):
        return self.title


# # 园区管理者
# class GardenUser(models.Model):
#     # 园区管理人员
#     username = models.CharField(u'名字', max_length=20, blank=True, null=True)
#     # 人员电话
#     mobile = models.CharField(u'电话', max_length=20, blank=True, null=True)
#     gender = models.CharField(u'性别', max_length=5, blank=True, null=True)
#     class Meta:
#         verbose_name = '园区管理者'
#         verbose_name_plural = verbose_name
#     def __str__(self):
#         return self.username




# 园区表
class GardenManage(models.Model):
    name = models.CharField(u'园区名称', max_length=20, blank=True, null=True)
    addr = models.CharField(u'园区地址', max_length=20, blank=True, null=True)
    area = models.CharField(u'园区面积', max_length=20, blank=True, null=True)
    # user = models.ForeignKey(GardenUser,blank=True, null=True,verbose_name=u'园区管理者')
    crop = models.CharField(u'园区作物', max_length=20, blank=True, null=True)
    class Meta:
        verbose_name = '园区表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


# 园区分地表
class GardenArea(models.Model):
    name = models.CharField(u'地块名称', max_length=20, blank=True, null=True)
    user = models.ForeignKey(MyUser,blank=True, null=True,verbose_name=u'所属用户')
    manage = models.CharField(u'负责人', max_length=20, blank=True, null=True)
    garden = models.ForeignKey(GardenManage,blank=True, null=True,verbose_name=u'所属园区')
    location = models.CharField(u'地块坐标', max_length=100, blank=True, null=True)
    area = models.CharField('地块面积', max_length=50, blank=True, null=True)
    mobile = models.CharField(u'电话', max_length=20, blank=True, null=True)
    img = models.CharField(u'地块图片', max_length=200, blank=True, null=True)
    addr = models.CharField(u'地块地址',max_length=255, null=True, blank=True)
    desc = models.CharField(u'地块介绍', max_length=50, blank=True,null=True)
    upl_time = models.DateTimeField(u'创建时间', blank=True, null=True)

    class Meta:
        verbose_name = '园区分地表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


# 农场管理者
class FarmUser(models.Model):
    name = models.CharField(u'人员名字', max_length=20, blank=True, null=True)
    gender = models.CharField(u'性别', max_length=20, blank=True, null=True)
    mobile = models.CharField(u'联系方式', max_length=20, blank=True, null=True)
    upl_time = models.DateTimeField(u'创建时间', blank=True, null=True)

    class Meta:
        verbose_name = '农场管理者'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
    


# 农场表
class FarmList(models.Model):
    name = models.CharField(u'农场名称', max_length=20, blank=True, null=True)
    user = models.ForeignKey(MyUser,blank=True, null=True,verbose_name=u'所属用户')
    manage_user = models.ForeignKey(FarmUser,blank=True, null=True,verbose_name=u'农场负责人')
    garden = models.ForeignKey(GardenArea,blank=True, null=True,verbose_name=u'所属地块')
    area = models.CharField('农场面积', max_length=50, blank=True, null=True)
    curr_var = models.CharField('当前品种', max_length=50, blank=True, null=True)
    farm_img = models.CharField(u'农场图片', max_length=200, blank=True, null=True)
    addr = models.CharField(u'农场地址',max_length=255, null=True, blank=True)
    location = models.CharField(u'经纬度', max_length=50, blank=True, null=True)
    farm_desc = models.CharField(u'农场介绍', max_length=50, blank=True,null=True)
    upl_time = models.DateTimeField(u'创建时间', blank=True, null=True)

    class Meta:
        verbose_name = '农场表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name



# 采摘发布
class Pick_Pub(models.Model):
    farm = models.ForeignKey(FarmList, blank=True, null=True, verbose_name=u'所属农场',related_name='farms')
    pick_s = models.DateTimeField(u'采摘开始', blank=True, null=True)
    pick_e = models.DateTimeField(u'采摘结束', blank=True, null=True)
    name = models.CharField(u'采摘名称', max_length=20, blank=True, null=True)
    addr = models.CharField(u'种植地址', max_length=20, blank=True, null=True)
    scale = models.CharField(u'种植规模', max_length=20, blank=True, null=True)
    ripe_time = models.DateTimeField(u'成熟日期', blank=True, null=True)
    company = models.CharField(u'采摘企业', max_length=20, blank=True, null=True)
    pick_img = models.CharField(u'农场图片', max_length=200, blank=True, null=True)
    upl_time = models.CharField(u'采摘时间', max_length=200,blank=True, null=True)
    hidden = models.BooleanField(default=False,verbose_name="是否隐藏")

    class Meta:
        verbose_name = '采摘发布'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


# 个人采摘
class Person_Pick(models.Model):
    farm = models.ForeignKey(FarmList, blank=True, null=True, verbose_name=u'所属农场',related_name='farms2')
    name = models.CharField(u'采摘人员', max_length=20, blank=True, null=True)
    var = models.CharField(u'品种', max_length=20, blank=True, null=True)
    num = models.CharField(u'数量', max_length=20, blank=True, null=True)
    upl_time = models.DateTimeField(u'采摘时间', blank=True, null=True)

    class Meta:
        verbose_name = '个人采摘'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name





# 销售管理
class Sell_Manage(models.Model):
    farm = models.ForeignKey(FarmList, blank=True, null=True, verbose_name=u'所属农场',related_name='farms1')
    name = models.CharField(u'客户名称', max_length=20, blank=True, null=True)
    num = models.CharField(u'数量', max_length=20, blank=True, null=True)
    money = models.CharField(u'金额', max_length=20, blank=True, null=True)
    upl_time = models.DateTimeField(u'创建时间', blank=True, null=True)

    class Meta:
        verbose_name = '销售管理'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


# 库存管理
class Store_Manage(models.Model):
    name = models.CharField(u'物料名称', max_length=20, blank=True, null=True)
    rtype = models.CharField(u'物料类别', max_length=20, blank=True, null=True)
    spec = models.CharField(u'规格', max_length=20, blank=True, null=True)
    rese = models.CharField(u'库存', max_length=20, blank=True, null=True)
    farm = models.ForeignKey(FarmList,blank=True, null=True,verbose_name=u'所属农场')
    upl_time = models.DateTimeField(u'创建时间', blank=True, null=True)

    class Meta:
        verbose_name = '地块库存表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name



# 区域种植统计
class Areacrop(models.Model):
    cropname = models.CharField(u'作物名称', max_length=20, blank=True, null=True)
    area = models.ForeignKey(GardenArea,blank=True, null=True,verbose_name=u'所属地块')
    crop_count = models.CharField(u'作物数量', max_length=20, blank=True, null=True)
    upl_time = models.DateTimeField(u'种植时间', blank=True, null=True)
    end_time = models.DateTimeField(u'结束时间', blank=True, null=True)

    class Meta:
        verbose_name = '区域作物表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.cropname


# 气象站预警记录表
class Warning_His(models.Model):
    equip_id = models.CharField(u'设备ID', max_length=20, blank=True, null=True)
    warning_info = models.CharField(u'预警说明', max_length=20, blank=True, null=True)
    warning_data = models.CharField(u'预警记录', max_length=20, blank=True, null=True)
    upl_time = models.DateTimeField(u'预警时间', blank=True, null=True)

    class Meta:
        verbose_name = '气象站预警记录表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.equip_id



# 民宿表
class Hotel_Info(models.Model):
    name = models.CharField(u'民宿名字', max_length=20, blank=True, null=True)
    price = models.CharField(u'民宿价格', max_length=20, blank=True, null=True)
    intro = models.CharField(u'民宿简介',max_length=255, null=True, blank=True)
    addr = models.CharField(u'民宿地址',max_length=255, null=True, blank=True)
    location = models.CharField(u'经纬度', max_length=50, blank=True, null=True)
    person = models.CharField(u'法人代表',max_length=255, null=True, blank=True)
    hotel_img = models.CharField(u'民宿封面', max_length=200, blank=True, null=True)
    hotel_tel = models.CharField(u'联系方式', max_length=20, blank=True, null=True)
    upl_time = models.DateTimeField(u'发布时间',default=timezone.now)
    # 是否隐藏
    hidden = models.BooleanField(default=False,verbose_name="是否隐藏")
    # 发布用户
    author = models.ForeignKey(MyUser,verbose_name="作者")
    content = RichTextUploadingField('民宿详情',null=True, blank=True)

    class Meta:
        verbose_name = '民宿表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


# 旅游信息表
class Sightsee_Info(models.Model):
    name = models.CharField(u'景点名字', max_length=20, blank=True, null=True)
    price = models.CharField(u'景点价格', max_length=20, blank=True, null=True)
    desc = models.CharField(u'景点简介',max_length=255, null=True, blank=True)
    location = models.CharField(u'经纬度', max_length=50, blank=True, null=True)
    addr = models.CharField(u'景点位置', max_length=50, blank=True, null=True)
    sightsee_stime = models.CharField(u'景区开放时间', max_length=50, blank=True, null=True)
    sightsee_etime = models.CharField(u'景区结束时间', max_length=50, blank=True, null=True)
    sightsee_img = models.CharField(u'景点图片', max_length=200, blank=True, null=True)
    sightsee_tel = models.CharField(u'联系方式', max_length=20, blank=True, null=True)
    upl_time = models.DateTimeField(u'发布时间',default=timezone.now)
    # 是否隐藏
    hidden = models.BooleanField(default=False,verbose_name="是否隐藏")
    # 发布用户
    author = models.ForeignKey(MyUser,verbose_name="作者")
    content = RichTextUploadingField('景点详情',null=True, blank=True)

    class Meta:
        verbose_name = '景点信息表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

    


# 民宿照片表
class Hotel_Photo(models.Model):
    hotel = models.ForeignKey(Hotel_Info, blank=True, null=True, verbose_name=u'所属民宿')
    upl_time = models.DateTimeField(u'上传时间', default=timezone.now)
    addr = models.CharField(u'照片路径', max_length=200, blank=True, null=True)
    
    def __str__(self):
       return self.addr
    class Meta:
        verbose_name = u'民宿照片表'
        verbose_name_plural = verbose_name
        ordering = ['-upl_time']
        get_latest_by = 'upl_time'



# 图片信息表
class Pic_Info(models.Model):
    pic_user = models.ForeignKey(MyUser, blank=True, null=True, verbose_name=u'图片用户')
    locat1 = models.CharField(u'图片东北点', max_length=50, blank=True, null=True)
    locat2 = models.CharField(u'图片西南点', max_length=50, blank=True, null=True)
    pic_center = models.CharField(u'图片中心点', max_length=50, blank=True, null=True)
    addr = models.CharField(u'照片路径', max_length=200, blank=True, null=True)
    locat_info = models.CharField(u'图片框格信息', max_length=300, blank=True, null=True)
    upl_time = models.DateTimeField(u'上传时间', default=timezone.now)
    
    def __str__(self):
       return self.addr
    class Meta:
        verbose_name = u'图片信息表'
        verbose_name_plural = verbose_name
        ordering = ['-upl_time']
        get_latest_by = 'upl_time'


