[英]How can I display the data recieved from the backend in a more readable way?I use react for the Frontend
Here is my model:这是我的 model:
class Festival(models.Model):
name = models.CharField(max_length=100)
start_date = models.DateTimeField(blank=True, null=True, default=None)
end_date = models.DateTimeField(blank=True, null=True, default=None)
number_of_tickets = models.IntegerField(default=50000)
location = JSONField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
def format_start_date(self):
return self.start_date.strftime("The Festival will start on: %d %b %Y at: %H:%M:%S")
def format_end_date(self):
return self.end_date.strftime("The Festival will end on: %d %b %Y at: %H:%M:%S")
I try to display the output from format_start_date() function using the frontend.我尝试使用前端显示来自 format_start_date() function 的 output 。 how could i do that?我怎么能这样做? At the moment, in List.Item.Meta i access the item.start_date, but it displays the date in an unwanted way.目前,在 List.Item.Meta 我访问 item.start_date,但它以不想要的方式显示日期。 I want it to be more readable, by using format_start_date() function from Festival model.我希望它更具可读性,通过使用来自 Festival model 的 format_start_date() function。 Is it possible?可能吗? if it isn't, what is the right way to do that: ex: if the date retrieved is "2020-06-12T12:00:00Z", i want to have in description: ""The Festival will start on: 12 06 2020 at: 12:00:00".如果不是,那么正确的方法是什么:例如:如果检索到的日期是“2020-06-12T12:00:00Z”,我想在描述中包含:“”节日将开始:12 2020 年 6 月 12:00:00”。
const IconText = ({ icon, text }) => (
<Space>
{React.createElement(icon)}
{text}
</Space>
);
const Festivals = (props) => {
return(
<List
itemLayout="vertical"
size="large"
pagination={{
onChange: page => {
console.log(page);
},
pageSize: 3,
}}
dataSource={props.data}
footer={
<div>
<b>ant design</b> footer part
</div>
}
renderItem={item => (
<List.Item
key={item.title}
actions={[
<IconText icon={StarOutlined} text="156" key="list-vertical-star-o" />,
<IconText icon={LikeOutlined} text="156" key="list-vertical-like-o" />,
<IconText icon={MessageOutlined} text="2" key="list-vertical-message" />,
]}
extra={
<img
width={272}
alt="logo"
src="https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png"
/>
}
>
<List.Item.Meta
avatar={<Avatar src={item.avatar} />}
title={<a href={item.href}>{item.name}</a>}
description={item.start_date}
/>
{item.content}
</List.Item>
)}
/>
)
}
export default Festivals;
I also tried using the function toLocaleDataString() from the Festival.js file, but it doesn't work.我还尝试使用 Festival.js 文件中的 function toLocaleDataString(),但它不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.