【django】校易论坛网源码customtag.py和initial.py

这是一个关于Django模板过滤器的实现,包括了时间距离现在的显示、商品新旧程度、交易模式、评论者和被评论者姓名等过滤器的定义。此外,还包含了Django项目的初始迁移文件,创建了多个模型,如Accountdetail、Adtype、Boss、City等。

'''
Created on Dec 3, 2019

@author: HLQP
'''
import datetime
import re

from django import template
from app.models import School, Player, Goods, Adtype
from distutils.msvc9compiler import Reg


register=template.Library()

# 过滤器  距今时间的表示“刚刚、几分钟前...几小时前...几天前...几个月前...超过一年显示时间”
@register.filter(name="tillnow")
def tillnow(value):
    
    # 截取掉微秒 并且转成datetime类型
    value=str(value)[0:-7]
    valuetime=datetime.datetime.strptime(value,"%Y-%m-%d %H:%M:%S")
    
    # 当前时间截取掉微秒 并且转成datetime类型
    nowtime=datetime.datetime.now()
    nowtime=nowtime.strftime("%Y-%m-%d %H:%M:%S")
    nowtime=datetime.datetime.strptime(nowtime,"%Y-%m-%d %H:%M:%S")
    
    # 距今时间 返回是datetime类型 小于一天返回格式"0:00:21" 大于一天返回格式"1 day, 0:04:17"
    timetill=nowtime-valuetime
    timestr=str(timetill)
    
    d="day"
    # 小于一天的情况下
    if d not in timestr:
        hourstr=re.findall(r"(\d\d?):\d\d:\d\d",timestr)
        minutestr=re.findall(r"\d\d?:(\d\d):\d\d",timestr)
        # 转成int类型
        hourint=int(str(hourstr)[2:-2])
        minuteint=int(str(minutestr)[2:-2])
        if hourint>0:
            return str(hourint)+"小时前"
        elif hourint==0 and minuteint>0:
            return str(minuteint)+"分钟前"
        else:
            return "刚刚"
    # 大于一天情况下  30天为一个月 365天为一年
    else:
        daystr=re.findall(r"(.+?)day.+?",timestr)
        dayint=int(str(daystr)[2:-2])
        if dayint<30:
            return str(dayint)+"天前"
        elif dayint>=30 and dayint<365:
            monthint=dayint//30
            return str(monthint)+"个月前"
        else:
            valuedate=valuetime.strftime("%Y-%m-%d") #超过一年显示日期
            return valuedate

# 过滤器 新旧程度
@register.filter(name="newlevel")
def newlevel(value):
    if value==10:
        return "全新"
    else:
        return str(value)+"成新"
    

# 过滤器 交易模式
@register.filter(name="tradmod")
def tradmod(value):
    if value==1:
        return "线上交易"
    elif value==-1:
        return "线下交易"
    else:
        return "中介交易"


# 过滤器 取评论者姓名
@register.filter(name="commentuser")
def commentuser(value):
    commentuser_id=value
    userinfo=Player.objects.get(id=commentuser_id)
    return userinfo.player_username
# 过滤器 获取被评论者姓名
@register.filter(name="replyname")
def replyname(value):
    reply_to_id=value
    userinfo=Player.objects.get(id=reply_to_id)
    return userinfo.player_username
        
# 过滤器 取评论者头像
@register.filter(name="commentuserpic")
def commentuserpic(value):
    commentuser_id=value
    userinfo=Player.objects.get(id=commentuser_id)
    return userinfo.player_photo

#过滤器 获取商品发布的学校名称
@register.filter(name="getschoolname")
def getschoolname(value):
    goods_school_id=value
    schoolinfo=School.objects.get(id=goods_school_id)
    return schoolinfo.school_name


# 过滤器 获取商品标题
@register.filter(name="gettitle")
def gettitle(value):
    collects_goods_id=value
    goodsinfo=Goods.objects.get(id=collects_goods_id)
    return goodsinfo.goods_title

#过滤器 获取商品id
@register.filter(name="getid")
def getid(value):
    collects_goods_id=value
    goodsinfo=Goods.objects.get(id=collects_goods_id)
    return goodsinfo.id

# 过滤器 根据收藏id获取发布学校名称
@register.filter(name="getschool")
def getschool(value):
    collects_goods_id=value
    goodsinfo=Goods.objects.get(id=collects_goods_id)
    schoolinfo=Scho

Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Traceback (most recent call last): File "D:\Python37\lib\site-packages\django\db\backends\utils.py", line 82, in _execute return self.cursor.execute(sql) File "D:\Python37\lib\site-packages\django\db\backends\oracle\base.py", line 523, in execute return self.cursor.execute(query, self._param_generator(params)) cx_Oracle.DatabaseError: ORA-02000: missing ALWAYS keyword The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\Python37\lib\site-packages\django\db\migrations\recorder.py", line 68, in ensure_schema editor.create_model(self.Migration) File "D:\Python37\lib\site-packages\django\db\backends\base\schema.py", line 345, in create_model self.execute(sql, params or None) File "D:\Python37\lib\site-packages\django\db\backends\base\schema.py", line 145, in execute cursor.execute(sql, params) File "D:\Python37\lib\site-packages\django\db\backends\utils.py", line 98, in execute return super().execute(sql, params) File "D:\Python37\lib\site-packages\django\db\backends\utils.py", line 66, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "D:\Python37\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers return executor(sql, params, many, context) File "D:\Python37\lib\site-packages\django\db\backends\utils.py", line 84, in _execute return self.cursor.execute(sql, params) File "D:\Python37\lib\site-packages\django\db\utils.py", line 90, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "D:\Python37\lib\site-packages\django\db\backends\utils.py", line 82, in _execute return self.cursor.execute(sql) File "D:\Python37\lib\site-packages\django\db\backends\oracle\base.py", line 523, in execute return self.cursor.execute(query, self._param_generator(params)) django.db.utils.DatabaseError: ORA-02000: missing ALWAYS keyword During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "D:\Python37\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line utility.execute() File "D:\Python37\lib\site-packages\django\core\management\__init__.py", line 413, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "D:\Python37\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv self.execute(*args, **cmd_options) File "D:\Python37\lib\site-packages\django\core\management\base.py", line 398, in execute output = self.handle(*args, **options) File "D:\Python37\lib\site-packages\django\core\management\base.py", line 89, in wrapped res = handle_func(*args, **kwargs) File "D:\Python37\lib\site-packages\django\core\management\commands\migrate.py", line 246, in handle fake_initial=fake_initial, File "D:\Python37\lib\site-packages\django\db\migrations\executor.py", line 91, in migrate self.recorder.ensure_schema() File "D:\Python37\lib\site-packages\django\db\migrations\recorder.py", line 70, in ensure_schema raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc) django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (ORA-02000: missing ALWAYS keyword) 什么问题
最新发布
08-22
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

py编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值