How to speed up my script

Hey! I have a script, but it is very long (1 hour), how to make the script faster, help me please!

for new in Bet.objects.filter(score='-').values(): 
            model_new = Bet.objects.get(id=new['id'])
            title_new = model_new.title
            name_command = model_new.name_command
            p1= int(float(model_new.p1) * 10) / 10
            X = int(float(model_new.X) * 10) / 10
            p2 = int(float(model_new.p2) * 10) / 10
            for old in Bet.objects.exclude(score='-').values(): 
                model = Bet.objects.get(id=old['id'])
                title_old = model.title
                p1_old = int(float(model.p1) * 10) / 10
                X_old = int(float(model.X) * 10) / 10
                p2_old = int(float(model.p2) * 10) / 10
                if title_new == title_old and p1 == p1_old and X == X_old and p2 == p2_old:

You’re iterating over all the objects and then doing a query for that same object. These two lines can be replaced by:

for model_new in Bet.objects.filter(score='-'): 

Then, even worse, you have the next loop indented under the first one, while making the same mistake regarding the duplicated queries. You’re iterating through an entire table for each entry in the first table.

This is really bad:

You need to restructure your logic for what you’re trying to do with those two loops.
I can’t quite figure out what you’re trying to achieve there, but there’s definitely a better way of handling this, whatever this is.

Thank you very much, you helped me