简体   繁体   English

当我在模板中显示数据时,如何解决 Django 中的价格错误?

[英]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 .我正在尝试在印度编号系统中转换Laccrore的价格。 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 名称, projectdetailsOneToOne关系:

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.

相关问题 为什么我在 django 教程中收到此模板错误? - Why am I receiving this Template error in my django tutorial? 迁移 Django 模型时如何解决错误? - How can I solve an error when I migrate my Django models? 当我尝试执行 django 模型迁移命令时出现错误 - python manage.py 迁移。 如何解决这个错误? - I am getting an error in when i am trying to execute django models migrate command - python manage.py migrate . How to solve this error? 当我在 Django 中运行我的服务器时,我收到模板不存在 - I am getting Template Does Not Exist at / when I'm running my server in Django 我正在尝试下载 Django-heroku。 但我收到此错误:找不到 pg_config 可执行文件。,如何解决? - I am trying to download Django-heroku. But I am getting this Error: pg_config executable not found., how to solve it? 展平 JSON 文件时出现 KeyError。 我该如何解决这个问题? - I am getting a KeyError when flattening my JSON file. How do I solve this? 如何在模板渲染渲染 django 期间解决此问题错误? - How can i solve this issue error during template rendering rendering django? 当模板确实存在时,为什么在 Django 4.0 中出现 TemplateDoesNotExist 错误? - Why am I getting a TemplateDoesNotExist error in Django 4.0 when the template does exist? Django 应用程序未在模板中显示数据 - Django app not displaying data in template Django 循环数据未显示在模板中 - Django for loop data not displaying in template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM