Beispiel #1
0
class Userinfo(models.Model):
    openid = models.CharField(max_length=200, default='')
    image_path = time.strftime('images/%Y/%m/%d')
    avatarUrl = models.ImageField(upload_to=help.PathAndRename(image_path),
                                  verbose_name="头像",
                                  max_length=500)
    city = models.CharField('城市', max_length=20, default='')
    country = models.CharField('国家', max_length=20, default='')
    gender = models.CharField('姓别',
                              max_length=1,
                              choices=[("0", "未知"), ("1", "男"), ("2", "女")],
                              default='0')
    language = models.CharField('语言', max_length=20, default='')
    nickName = models.CharField('名称', max_length=20, default='')
    province = models.CharField('省份', max_length=20, default='')
    pub_date = models.DateTimeField('时间', auto_now_add=True)
    login_count = models.IntegerField('登陆次数', default=1)
    login_date = models.DateTimeField('最后登陆时间', auto_now=True)

    def avatar_picurl(self):
        return '<img src="%s" width="%d" height="%d"/>' % (self.avatarUrl, 80,
                                                           60)

    avatar_picurl.allow_tags = True
    avatar_picurl.short_description = '头像'

    def __str__(self):
        return self.nickName

    class Meta:
        verbose_name = "用户"
        verbose_name_plural = "6.用户"
Beispiel #2
0
class Lession(models.Model):
    title = models.CharField('课程名称', max_length=200)
    image_path = time.strftime('images/%Y/%m/%d')
    picurl = models.ImageField(upload_to=help.PathAndRename(image_path),
                               verbose_name="图片",
                               max_length=500)
    price = models.FloatField('课程价格', default='0.00')
    exercise_time = models.IntegerField('课程时间',
                                        default=0,
                                        choices=LESSION_DATE_CHOICES)
    address = models.CharField('地址', max_length=1000)
    pub_date = models.DateTimeField('发布时间', auto_now_add=True)
    teach_ids = models.ManyToManyField(Teach, verbose_name="选择教练")

    def __str__(self):
        return self.title

    def get_teachs(self):
        return " ".join([p.title for p in self.teach_ids.all()])

    get_teachs.short_description = '教练'

    class Meta:
        ordering = ['-pub_date']
        verbose_name = "课程"
        verbose_name_plural = "B.课程"
Beispiel #3
0
class Writings(models.Model):
    title = models.CharField('标题', max_length=200, default='')
    shorttitle = models.CharField('副标题', max_length=200, default='')
    image_path = time.strftime('images/%Y/%m/%d')
    picurl = models.ImageField('', upload_to=help.PathAndRename(image_path))
    #content = models.TextField('内容',default='')
    content = HTMLField()
    view = models.IntegerField('阅读量', default=0)
    pub_date = models.DateTimeField('发布时间')

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "资讯"
        verbose_name_plural = "8.资讯"
Beispiel #4
0
class Player(models.Model):
    username = models.CharField('姓名', max_length=200)
    eng_name = models.CharField('英文名', max_length=300, default='')
    height = models.IntegerField(
        '身高cm',
        default=120,
        validators=[MaxValueValidator(300),
                    MinValueValidator(100)])
    age = models.IntegerField(
        '年龄',
        default=30,
        validators=[MaxValueValidator(100),
                    MinValueValidator(10)])
    level = models.CharField('级别', max_length=50, choices=LEVEL_CHOICES)
    rule = models.CharField('赛制', max_length=50, choices=[("自由搏击", "自由搏击")])
    nationality = models.CharField('国籍', max_length=20, blank=True)
    alias = models.CharField('绰号', max_length=50, blank=True)
    place = models.CharField('场馆', max_length=50, blank=True)
    history = models.CharField('历史战绩', max_length=2000, blank=True)
    glory = models.CharField('头衔', max_length=2000, blank=True)
    summary = models.TextField('简介', max_length=2001, blank=True)

    def __str__(self):
        return self.username

    image_path = time.strftime('images/%Y/%m/%d')
    picurl = models.ImageField(upload_to=help.PathAndRename(image_path),
                               verbose_name="照片")
    pub_date = models.DateTimeField('发布时间', auto_now_add=True)

    def admin_picurl(self):
        return '<img src="%s%s" width="%d" height="%d"/>' % (
            settings.MEDIA_URL, self.picurl, 80, 60)

    admin_picurl.allow_tags = True
    admin_picurl.short_description = '照片'

    class Meta:
        verbose_name = "选手"
        verbose_name_plural = "5.选手"
Beispiel #5
0
class Place(models.Model):
    title = models.CharField('场馆名称', max_length=500, default='')
    image_path = time.strftime('images/%Y/%m/%d')
    picurl = models.ImageField(upload_to=help.PathAndRename(image_path),
                               verbose_name="场馆座位图",
                               max_length=500)
    address = models.CharField('地址', max_length=500, default='')
    pub_date = models.DateTimeField('更新时间', auto_now_add=True)

    def p_picurl(self):
        url = '<img src="%s%s" width="%d" height="%d"/>' % (
            settings.MEDIA_URL, self.picurl, 200, 150)
        return '<a href="%s%s">%s</a>' % (settings.MEDIA_URL, self.picurl, url)

    p_picurl.allow_tags = True
    p_picurl.short_description = '场馆座位图'

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "场馆"
        verbose_name_plural = "3.场馆"
Beispiel #6
0
class Teach(models.Model):
    title = models.CharField('教练名称', max_length=200)
    image_path = time.strftime('images/%Y/%m/%d')
    picurl = models.ImageField(upload_to=help.PathAndRename(image_path),
                               verbose_name="教练照片",
                               max_length=500)
    summary = models.TextField('简介', max_length=2001, blank=True)
    pub_date = models.DateTimeField('发布时间', auto_now_add=True)

    def p_picurl(self):
        url = '<img src="%s%s" width="%d" height="%d"/>' % (
            settings.MEDIA_URL, self.picurl, 80, 80)
        return '<a href="%s%s">%s</a>' % (settings.MEDIA_URL, self.picurl, url)

    p_picurl.allow_tags = True
    p_picurl.short_description = '教练照片'

    def __str__(self):
        return self.title

    class Meta:
        ordering = ['-pub_date']
        verbose_name = "教练"
        verbose_name_plural = "C.教练"
Beispiel #7
0
class Article(models.Model):
    tid = models.ForeignKey(Title,
                            verbose_name='赛事分类',
                            on_delete=models.CASCADE)
    title = models.CharField('标题', max_length=200)
    score = models.CharField('比分', max_length=200, default='')
    image_path = time.strftime('images/%Y/%m/%d')
    #picurl = models.ImageField(upload_to='upload/%s' % image_path )
    picurl = models.ImageField(upload_to=help.PathAndRename(image_path))
    video = models.CharField(max_length=1000)
    game_date = models.DateTimeField('比赛时间')
    pub_date = models.DateTimeField('发布时间', auto_now_add=True)
    play_count = models.IntegerField('播放量', default=0)
    #player_a = models.ForeignKey(Player,related_name='对战选手A')
    #player_a = models.IntegerField(default=0,choices=[(0, '----------')])
    #player_b = models.IntegerField(default=0,choices=[(0, '----------')])
    tmp = [(p.id, p.username) for p in Player.objects.all()]
    player_a = models.IntegerField(default=0, choices=tmp)
    player_b = models.IntegerField(default=0, choices=tmp)

    place = [(p.id, p.title) for p in Place.objects.all()]
    place = [(0, '')] + place
    pid = models.IntegerField('场馆', default=0, choices=place)

    APPROVAL_CHOICES = (
        ('0', ''),
        ('1', '首页'),
    )
    attr = models.CharField('自定义属性',
                            default='',
                            choices=APPROVAL_CHOICES,
                            max_length=2)

    def __str__(self):
        return self.title

    def play_count_name(self):
        return help.millions_formatter(self.play_count)

    play_count_name.short_description = '播放量'

    def was_published_recently(self):
        now = timezone.now()
        return now - datetime.timedelta(days=1) <= self.pub_date <= now

    was_published_recently.admin_order_field = 'pub_date'
    was_published_recently.boolean = True
    was_published_recently.short_description = '是否最新发布'

    def place(self):
        tmp = Place.objects.get(pk=self.pid)
        return tmp.title

    place.short_description = '场馆'

    def __init__(self, *args, **kwargs):
        super(Article, self).__init__(*args, **kwargs)
        tmp = [(p.id, p.username) for p in Player.objects.all()]
        self._meta.get_field('player_a').choices = tmp  #动态添加select
        self._meta.get_field('player_b').choices = tmp  #动态添加select

    class Meta:
        verbose_name = "赛事对决"
        verbose_name_plural = "2.赛事对决"
Beispiel #8
0
 def test(self):
     tmp = False
     print("fefef")
     print(help.test1())
     print(help.PathAndRename('11.jpg'))
     self.assertEqual(tmp, False)