204👍
✅
F objects.
from django.db.models import F
stale_activities = Activity.objects.filter(updated__gte=F('added_toSolr_date'))
4👍
The solution of Yuji Tomita, unfortunately, didn’t work.
Consider a model below:
class list(models.Model):
text = models.CharField(max_length=140)
created = models.DateTimeField()
modified = models.DateTimeField()
Queryset:
my_list = todolist.objects.order_by('created').filter(created__gte=F('modified'))
Template:
{% if my_list %}
{% for list in my_list %}
{{ list.text}}
{% endfor %}
{% else %}
<p>there is no list</p>
{% endif %}
In the end I get an empty list, but I know, it is not correct. I have also used the following inside the template (without queryset filter):
{% if list.created|date:'d m y h:i:s' == list.modified|date:'d m y h:i:s' %}
It worked, but I would prefer to see a more elegant solution.
- [Django]-How to test "render to template" functions in django? (TDD)
- [Django]-How can I test https connections with Django as easily as I can non-https connections using 'runserver'?
- [Django]-MySQL "incorrect string value" error when save unicode string in Django
Source:stackexchange.com