Cannot resolve keyword 'ir' into field. Choices are: category, category_id, date, description, id, is_on_main, name, price, url

for some reason it does not see the ir field, although it exists.

def index(request):
    data = (
    categ = Category.objects.all()
    return render(request,'magazin/index.html',{'data' : data,'cat' : categ})

class Product(models.Model):
    is_on_main = models.BooleanField(default=False)
    category = models.ForeignKey(Category, on_delete = models.CASCADE)
    name = models.CharField(max_length=50)
    price = models.IntegerField()
    date = models.DateTimeField(null = True,auto_now=True)
    url = models.SlugField(max_length=100,unique=True,null=True)
    description = models.TextField(max_length=2000,default='Описание')
    ir = - datetime.timedelta(minutes=30)
    def __str__(self):
    class Meta:
        ordering = '-date', 

index.html(part with data)

{% for i in data %}
           <h4><b>НАЗВАНИЕ: </b>{{}}</h4>
           <h4><b>ЦЕНА: </b>{{i.price}}</h4>
           <a href="{% url 'detail' %}">ПОДРОБНЕЕ</a>
           {% if >= %}
                <h1 class="r">НЕДАВНО В ПРОДАЖЕ!</h1> 
           {% endif %}                                                                                                                            

thank you in advance

>Solution :

ir declaration in your Product model is not valid. Try declaring it like:

ir = models.DateTimeField(default=( - datetime.timedelta(minutes=30)))

Leave a Reply