Django Unchained Edit Latest Page

# Get the latest object based on 'created_at' field latest_object = MyModel.objects.latest('created_at')

from myapp.models import MyModel

latest_object = MyModel.objects.order_by('id').last() # Or 'pk' for primary key django unchained edit latest

# Now you can edit it latest_object.some_field = 'new value' latest_object.save() However, latest() method returns a single object based on ordering by a field (or fields) specified. If you want to get the latest based on a specific ordering (e.g., id , created_at ), ensure your model or query is ordered accordingly. If your model does not have a specific created_at or similar field, or if you simply want to get the "latest" based on the natural ordering of your database (typically by id if you're using autoincrementing IDs): # Get the latest object based on 'created_at'

If you could provide more context or clarify your question further, I might be able to offer more targeted assistance. from myapp

from myapp.models import MyModel

© 2020 • Powered by FindidFB DMCA.com Protection Status