Python Django Template Questions

Asked 1 years ago, Updated 1 years ago, 112 views

dic =
[{'name': Knives Out', 'dt_area': Kim Tae-hyung-kwan [Hall 1] 6th floor', 'start_time': '22:15', 'seat': '139 remaining seats', 'area': 'CGV Gangnam',
 {'name': 'Naves Out', 'dt_area': 'Kim Tae-hyung-kwan [1st Building] 6th floor', 'start_time': '24:55', 'seat': '144 remaining seats', 'area': 'CGV Gangnam', '},
 {'name': 'Frozen', 'dt_area': 'Kim Tae-hyung-gwan [1st Building] 6th floor', 'start_time': '27:35', 'seat': 'Remaining 143 seats', 'area': 'CGV Gangnam',
 {'name': 'Frozen', 'dt_area': '6th floor of the BTS [Laser]', 'start_time': '12:30', 'seat': '25 remaining seats', 'area': 'CGV Gangnam'}]

From the template in the longs

Obtain the following arrangement from db.

Use template tags to

Subtracting values one by one If the key value of the previous name and the key value of the current name are the same,

I tried to print out the duplicate value, but I didn't know how to approach it

I can't think of anything If you want to print it out like the output example below, how do you do it?

Is there any access? Help me!

Or is it Is there a way to solve it in Python instead of template tags?

For example, the output looks like this.

knives out
Kim Taehyung Hall[1st Building] 6th Floor
'22:15
139 seats remaining
Kim Taehyung Hall[1st Building] 6th Floor
'24:55
144 seats remaining

Frozen
Kim Taehyung Hall[1st Building] 6th Floor
27:35
143 seats remaining
BTS V-Kwan [Laser] 6th floor
12:30
25 seats remaining

python django-view

2022-09-22 08:21

1 Answers

The itertools module has a groupby function.

If you group by name as shown below, it is grouped according to name.

dic =[{'name']: 'Naves out', 'dt_area': 'Kim Tae-hyung-kwan [1st building] 6th floor', 'start_time': '22:15', 'seat': '139 remaining seats', 'area': 'CGV Gangnam',
 {'name': 'Knives Out', 'dt_area': 'Kim Tae-hyung-kwan [1st Building] 6th floor', 'start_time': '24:55', 'seat': '144 remaining seats', 'area': 'CGV Gangnam', },
 {'name': 'Frozen', 'dt_area': 'Kim Tae-hyung-gwan [1st Building] 6th floor', 'start_time': '27:35', 'seat': 'Remaining 143 seats', 'area': 'CGV Gangnam',
 {'name': 'Frozen', 'dt_area': '6th floor of the BTS [Laser]', 'start_time': '12:30', 'seat': '25 remaining seats', 'area': 'CGV Gangnam'}]

for k, g in it.groupby(dic, lambda e:e['name']):
    print('{} {}'.format(k, list(g)))

Knives Out [{'name': Knives Out', 'dt_area': Kim Tae-hyung's [1st floor], 'start_time': '22:15', 'seat': 139 remaining seats', 'area': 'CGV Gangnam'}, {'name': Knives Out', 'dt_area': 'Gangnam_area': Kim Tae-hyung's seat: 'Cart_time'sit: '145, '6th floor'
Frozen [{'name': Frozen', 'dt_area': Kim Tae-hyung-gwan [Gwan 1] 6th floor, 'start_time': '27:35', 'seat': 'remaining 143 seats', 'area': 'CGV Gangnam', {'name': 'Frozen', 'dt_area': 'Gangnam_area': 'Cart_time' 6th floor: 'Cart_time', '12', 'Cart'



2022-09-22 08:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.