Need help in understanding this code

for date in HabitLog.objects.values_list('date',flat=True).distinct():
                HabitLog.objects.filter(pk__in=HabitLog.objects.filter(date=date).values_list('id',flat=True)[1:]).delete()
                print('Duplicate Deleted')

What is it about this code that you don’t understand?

Break it apart into parts (individual lines) and then individual function calls. Look at it step by step.

First line:

What does this line do?

Second line:

What does this line do?