A_K
A_K

Reputation: 912

How to update status in Admin from a drop downlist

Hi I have in my order Model a status where I can choose the status of the order.

I want to be able to update the status from the external display of the admin instead of going inside of the detail view of the order.

Here is the models.py

class Order(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL,
                             on_delete=models.CASCADE)
    ref_code = models.CharField(max_length=20, blank=True, null=True)
    items = models.ManyToManyField(OrderItem)
    start_date = models.DateTimeField(auto_now_add=True)
    ordered_date = models.DateTimeField()
    ordered = models.BooleanField(default=False)
    status = models.CharField(max_length=50,
                              choices=[('pending', 'Pending'), ('ofd', 'Out For Delivery'), ('recieved', 'Recieved')],
                              default='pending')

Here is the admin.py

class OrderAdmin(admin.ModelAdmin):
    list_display = ['user', 'ordered', 'ordered_date', 'status','ref_code']

Upvotes: 0

Views: 56

Answers (1)

Iain Shelvington
Iain Shelvington

Reputation: 32294

If you mean you want to be able to update the status from the list page, you can set list_editable on your admin class

class OrderAdmin(admin.ModelAdmin):
    list_editable = ['status']
    ...

Upvotes: 1

Related Questions