[英]How to solve price error in Django when I am displaying data in my template?
I am trying to convert price in Lac
and crore
in Indian numbering system .我正在尝试在印度编号系统中转换
Lac
和crore
的价格。 Value is stored in minprice' in this format (
10000000 ), then it will display on my homepage in this format (
1 cr ), but I am getting this error (
'>=' not supported between instances of 'NoneType' and 'int' `) in my website whenever I open any project.值
minprice' in this format (
), then it will display on my homepage in this format (
1 cr ), but I am getting this error (
'NoneType' 和 'int 的实例之间不支持 '>=' ' `) 每当我打开任何项目时都会出现在我的网站中。 How can I solve this issue?我该如何解决这个问题?
Here is my models.py
file:这是我的
models.py
文件:
class Project(models.Model):
name=models.CharField(null=True,
max_length=114,
help_text=f"Type: string, Values: Enter Project Name.")
slug=models.SlugField(null=True,
unique=True,
max_length=114,
help_text=f"Type: string, Values: Enter Project Slug.")
here is my related model name, project
has OneToOne
relation with details
:这是我相关的 model 名称,
project
与details
有OneToOne
关系:
class Detail(models.Model):
project = models.OneToOneField(Project, related_name='project_details', on_delete=models.CASCADE)
minprice = models.IntegerField(null=True,
blank=True,
verbose_name="Minimum Price",
help_text=f"Type: Int, Values: Enter Minimum Price")
maxprice = models.IntegerField(null=True,
blank=True,
verbose_name='Maximum Price',
help_text=f"Type: Int, Values: Enter Maximum Price")
@property
def min_price_tag(self):
if self.minprice >=1000 and self.minprice <=99999:
self.minprice=self.minprice//1000
return f"{self.minprice} K"
elif self.minprice>=100000 and self.minprice<=9999999:
self.minprice=self.minprice//100000
return f"{self.minprice} Lac"
else:
self.minprice=self.minprice/10000000
return f'{self.minprice} Cr'
return str(self.minprice) if self.minprice is not None else ""
@property
def max_price_tag(self):
if self.maxprice >=1000 and self.maxprice <=99999:
self.maxprice=self.maxprice//1000
return f"{self.maxprice} K"
elif self.maxprice>=100000 and self.maxprice<=9999999:
self.maxprice=self.maxprice//100000
return f"{self.maxprice} Lac"
else:
self.maxprice=self.maxprice/10000000
return f'{self.maxprice} Cr'
return str(self.maxprice) if self.maxprice is not None else ""
here is my project.html
file, where I am displaying the data这是我的
project.html
文件,我在其中显示数据
{% for i in project %}
<div class="col-md-3 col-sm-12">
<div class="single-property-box">
<a class="trend-right float-right">
<div class="trend-open">
<p>
₹ {{i.project_details.min_price_tag}} - ₹{{i.project_details.max_price_tag}}
</p>
</div>
</a>
</div>
</div>
{% endfor %}
The error might be occurring because you have set both the integer fields null=True, blank=True, make them required.可能会发生错误,因为您已将 integer 字段都设置为 null=True,blank=True,使它们成为必需。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.