g214/metadata/models.py

215 lines
6.7 KiB
Python

# coding=utf-8
from __future__ import unicode_literals
import uuid
from django.contrib.auth.models import User
from django.db import models
from django.utils import timezone
from base.models import Land
class Category(models.Model):
NAME_CHOICES = (
(u'基础地理数据', u'基础地理数据'),
(u'遥感数据', u'遥感数据'),
(u'G214国道', u'G214国道'),
(u'花石峡冻土观测站', u'花石峡冻土观测站'),
(u'青海冻土观测基地', u'青海冻土观测基地'),
)
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
name = models.CharField('名称', max_length=128, choices=NAME_CHOICES)
created = models.DateTimeField(auto_now=True)
updated = models.DateTimeField(auto_now=True)
def __unicode__(self):
return self.name
class Meta:
verbose_name_plural = u'分类'
# 元数据作者
class Contact(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
# 姓名
name = models.CharField(u'姓名', max_length=50)
# 单位
unit = models.CharField(u'单位', max_length=128)
# 邮件
mail = models.EmailField(u'邮箱', max_length=50)
# 电话
phone = models.CharField(u'电话', max_length=50)
created = models.DateTimeField(u'创建时间', auto_now=True)
updated = models.DateTimeField(u'更新时间', auto_now=True)
def __unicode__(self):
return self.name
class Meta:
verbose_name_plural = u'元数据作者'
# tag
class Tag(models.Model):
TYPE_CHOICES = (
(1, u'主题'),
(2, u'学科'),
(3, u'位置'),
)
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
name = models.CharField(max_length=100)
type = models.IntegerField(choices=TYPE_CHOICES)
def __unicode__(self):
return self.name
class Meta:
verbose_name_plural = u'标签'
class Metadata(models.Model):
# 数据分类
category = models.ForeignKey(Category, verbose_name='数据分类')
authors = models.ManyToManyField(Contact, related_name="authors", verbose_name='元数据作者', blank=True)
contributor = models.ManyToManyField(Contact, related_name="contributor", verbose_name='数据贡献者', blank=True)
manager = models.ManyToManyField(Contact, related_name="manager", verbose_name='数据管理者', blank=True)
land = models.ForeignKey(Land, verbose_name='试验场', blank=True, null=True)
tags = models.ManyToManyField(Tag)
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4, editable=False)
title_cn = models.CharField(u'标题', max_length=128)
# 数据集摘要
abstract = models.TextField(u'数据集摘要')
# 数据源描述
description = models.TextField(u'数据源描述')
# 目录
table_of_contents = models.CharField(u'目录', max_length=128, blank=True)
# 缩略图
thumbnail = models.ImageField('上传图片', upload_to='images', blank=True)
# 地理范围东
acq_lon_east = models.FloatField(u'地理范围东', blank=True)
# 地理范围南
acq_lat_south = models.FloatField(u'地理范围南', blank=True)
# 地理范围西
acq_lon_west = models.FloatField(u'地理范围西', blank=True)
# 地理范围北
acq_lat_north = models.FloatField(u'地理范围北', blank=True)
# 点击量
hit_count = models.IntegerField(u'点击量', default=0)
# 出版信息
publisher = models.CharField(u'出版信息', max_length=200, blank=True)
created = models.DateTimeField(u'创建时间', auto_now=True)
updated = models.DateTimeField(u'更新时间', auto_now=True)
# 是否观测数据
type = models.IntegerField(u'是否观测数据', default=0)
def __unicode__(self):
return self.title_cn
def image_img(self):
if self.thumbnail:
return u'<img src="%s" />' % self.thumbnail.url
else:
return '(Sin image)'
image_img.short_description = 'Image'
image_img.allow_tags = True
class Meta:
verbose_name_plural = u'元数据'
# 数据实体
class DataEntity(models.Model):
# id
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
file_name = models.CharField('文件名', max_length=200)
# 原始文件名
origin_file_name = models.CharField('原文件名', max_length=200)
# 文件大小
file_size = models.IntegerField('文件大小')
created = models.DateTimeField('创建时间', auto_now=True)
updated = models.DateTimeField('更新时间', auto_now=True)
metadata = models.ForeignKey(Metadata)
class Meta:
verbose_name_plural = u'数据实体'
# 评论
class Comment(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
metadata = models.ForeignKey(Metadata)
user = models.ForeignKey(User)
content = models.TextField(blank=True, null=True)
created = models.DateTimeField(default=timezone.now, blank=True)
updated = models.DateTimeField(default=timezone.now, blank=True)
# 加入收藏
class Favorite(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey(User)
metadata = models.OneToOneField(Metadata)
created = models.DateField(u'创建时间', auto_now_add=True, null=True)
updated = models.DateField(u'更新时间', auto_now=True)
# 购物车
class Cart(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.OneToOneField(User)
class Order(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey(User)
real_name = models.CharField(u'真实姓名', max_length=200, null=True)
phone = models.CharField(u'电话', max_length=200, null=True)
email = models.CharField(u'邮箱', max_length=50, null=True)
unit = models.CharField(u'单位', max_length=200, null=True)
address = models.CharField(u'地址', max_length=200, null=True)
post_code = models.CharField(u'邮编', max_length=50, null=True)
purpose = models.TextField(null=True)
status = models.IntegerField(default=0)
class LineItem(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
quantity = models.IntegerField(default=0)
cart = models.ForeignKey(Cart, null=True)
metadata = models.OneToOneField(Metadata)
order = models.ForeignKey(Order, null=True)
class Navigation(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
name = models.CharField('名称', max_length=128)
order_by = models.IntegerField(default=0)
parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE)
def __unicode__(self):
return self.name