Delete rows or sort model if column value is less than given value?

I have a table model.

In one column of the table, the data is in the form - date-time. Dates may vary slightly.

How to compare the column of the model table through a loop or in some other way and (provided that the date in the column is less than a certain given date) delete the current row?

Delete those rows from the model if the value in the column (date time) of the table is less than the given one.

"value" = 2023-04-02 10:00:00

queryset_1_sorted = Model_1.objects.order_by("datetime" < "value")

               datetime  temper_1  temper_2  g_rashod temper_nv
0   2023-01-02 10:00:00     58.13     49.35    70.520       1.4
1   2023-01-02 11:00:00     57.44     49.12    89.805       1.4
2   2023-01-02 12:00:00     57.82     49.30    89.187       1.4
3   2023-01-02 13:00:00     58.08     49.62    89.079       1.4
4   2023-01-02 14:00:00     58.20     49.77    89.081       2.1

225 2023-10-02 19:00:00     65.67     53.90    87.998      -7.6
226 2023-10-02 20:00:00     66.80     54.98    87.970      -8.1
227 2023-10-02 21:00:00     67.37     55.53    87.946      -8.1
228 2023-10-02 22:00:00     67.76     55.87    87.973      -8.1
229 2023-10-02 23:00:00     68.02     56.09    87.942      -8.1

You use the filter function to find a set of rows matching a desired criteria. The output from filter is a queryset. You can then use the delete method on that queryset to delete those identified rows.

If you want more specific information, please post your model here. It’s going to be a lot easier to work through an answer in the context of your actual code.