syntax

1
your_model.objects.order_by('-pk')[0].delete()

example

1
2
3
4
5
#models.py
class test(models.Model):
    name = models.CharField(max_length=300, null=True, blank=True)
    def __str__(self):
        return self.name
1
2
3
4
5
6
7
#add data to model
>>> test.objects.create(name='mike')
<test: mike>
>>> test.objects.create(name='sik')
<test: sik>
>>> test.objects.create(name='bik')
<test: bik>
1
2
3
4
#delete the last data 

test.objects.order_by('-pk')[0].delete()
(1, {'core.test': 1})
1
2
3
#show all model data after deleting
>>> test.objects.all()
<QuerySet [<test: mike>, <test: sik>]>

we did this way because django does not support the Negative indexing!

English today is not an art to be mastered it's just a tool to use to get a result