I am doing a Sunburst chart Ticket booking app using django.In that the chart needs to show 3 layers of data like Events,Slots,Categories.i have already done the work but it doesnot allow duplicate event names and slot names so please check the code and give me idea . In my project there may be so many events can have same and slots of every events may have same β¦so give me code or idea to do it.
code:
def sunburst_chart(request):
events = event_master.objects.filter(client_id=request.user.id)
slots = event_slots.objects.filter(client_id=request.user.id)
categories = event_ticket_category.objects.filter(client_id=request.user.id)
data = []
for event in events:
eventslots = slots.filter(event_master_id=event.id)
if not eventslots:
data.append({'path_0': event.Event_Name})
else:
for slot in eventslots:
categories_slot = categories.filter(event_slots_id=slot.id)
if not categories_slot:
data.append({'path_0': event.Event_Name, 'path_1': slot.Slot_Name})
else:
for category in categories_slot:
data.append({'path_0': event.Event_Name, 'path_1': slot.Slot_Name, 'path_2': category.Category_Name})
df = pd.DataFrame(data)
fig = px.sunburst(df, path=['path_0', 'path_1', 'path_2'])
plot_html = fig.to_html(full_html=True)
context = {'plot_html': plot_html}
return render(request, 'K_ticket/sunburstChat.html', context)