I have an dictionary as follows:
defaultdict(None, {
'Category 1': [
{'id': 24, 'name': 'Video 1', 'cat_id': 16, 'tut_id': 14, 'description': ''},
{'id': 28, 'name': 'Video 5', 'cat_id': 16, 'tut_id': 14, 'description': ''}
],
'Category 3': [
{'id': 25, 'name': 'Video 3', 'cat_id': 18, 'tut_id': 14, 'description': ''},
{'id': 29, 'name': 'Video 6', 'cat_id': 18, 'tut_id': 14, 'description': ''}
],
'Category 2': [
{'id': 26, 'name': 'Video 2', 'cat_id': 17, 'tut_id': 14, 'description': ''},
{'id': 27, 'name': 'Video 4', 'cat_id': 17, 'tut_id': 14, 'description': ''}
]
})
And in my view I have next code:
video_id = int(request.POST.get('id', None))
cat_id = int(request.POST.get('cat_id', None))
cat_name = int(request.POST.get('cat_name', None))
tut_id = int(request.POST.get('tut_id', None))
I want to get next and previous item from the dictionary. If there are items onder same category get them, and if there are not, get the item from the next or previous category.
I have no idea how to start
Expected output
video_id = 3
cat_id = 18
cat_name = "Category 3"
tut_id = 14
next = {'id': 29, 'name': 'Video 6', 'cat_id': 18, 'tut_id': 14, 'description': ''}
prev = {'id': 28, 'name': 'Video 5', 'cat_id': 16, 'tut_id': 14, 'description': ''}
Any idea how to do that?