def detail(request, id_hash=None): hash = id_hash id = hashing.decode_id(id_hash) habit = get_object_or_404(Habit, id=id) habit.time_now = timezone.now() habit.hash = hash habit.timesince = timesince.timesince(habit.track_date) return render(request, 'detail.html', {'habit': habit})
def latest(request): latest_habits_list = Habit.objects.order_by('-pub_date')[:10] for item in latest_habits_list: item.time_now = timezone.now() item.hash = hashing.encode_id(item.id) item.timesince = timesince.timesince(item.track_date) context = Context({ 'latest_habits_list': latest_habits_list, }) return render(request, 'latest.html', context)