I'm a student studying Django. I want to calculate the number of days between the two specified dates. Currently, View has specified two variables and attempted a subtraction operation, but the following error is being output:
Could not parse the remainder: ' - today' from 'product.due_date|date:"Ymd" - today'
How should I solve this problem? I would appreciate it if you could give me an answer. Attached is models.py and View.py below.
views.py
def product_detail(request, id, product_slug=None):
current_category = None
categories = Category.objects.all()
products = Product.objects.all()
product = get_object_or_404(Product, product_code=id, slug=product_slug)
designated_object = Designated.objects.filter(rep_price='True')
element_object = Element.objects.all()
value_object = Value.objects.all()
today = DateFormat(datetime.now()).format('Ymd')
return render(request, 'zeronine/detail.html', {'product':product,
'products':products,
'current_category': current_category,
'categories':categories,
'designated_object': designated_object,
'element_object':element_object,
'value_object':value_object, 'today':today})
models.py
class Product(models.Model):
product_code = models.AutoField(primary_key=True)
username = models.ForeignKey(Member, on_delete=models.CASCADE, db_column='username')
category_code = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, related_name='products')
name = models.CharField(max_length=200, db_index=True)
slug = models.SlugField(max_length=200, db_index=True, unique=False, allow_unicode=True)
image = models.ImageField(upload_to='products/%Y/%m/%d', blank=True)
benefit = models.TextField()
detail = models.TextField()
target_price = models.IntegerField()
start_date = models.DateField()
due_date = models.DateField()
Created as {{product.due_date|date:"Ymd" - today}}
.