1

To create admin interface to edit some field, which is best practice? Customize default Django admin or create admin template?

I want to edit status field via admin. But others field, admin can't edit.. In this scenario can I write new view and template for admin or just customize the default admin panel?

class SendProduct(models.Model):
    PAYMENT_CHOICE = (
        ('A', 'Advanced'),
        ('C', 'COD'),
    )
    item_name = models.CharField(max_length=200)
    item_details = models.TextField()
    delivery_address = models.TextField()
    payment_type = models.CharField(max_length=1, choices=PAYMENT_CHOICE)
    payable_amount = models.IntegerField(default=0)
    delivery_charge = models.IntegerField(default=0)
    qr_code = models.ImageField(upload_to='qrcode', blank=True, null=True)
    user = models.ForeignKey(Profile, on_delete=models.CASCADE)
    status = models.IntegerField(default=0)
1
  • How is build the model you want to adapt ? you should add it if you want efficient help.
    – PRMoureu
    Sep 21, 2017 at 16:24

2 Answers 2

1

Excluding fields and make them read-only(admin.py). An example is given below

class SendProductAdmin(admin.ModelAdmin):
    exclude=("item_name ",)
    readonly_fields=('item_name', )

admin.site.register(SendProductAdmin)

Note that you can exclude as many fields as you want.

0

There is difference between the usage of admin panel and the views that you develop, the difference that you should pay attention is the admin panel is for staff users, the users that are inside company and organization and provide content to the end-users.

So who is going to work with that form? Decide on that base and what you want to do can be done both in admin panel and a developed view.

4
  • I have added my model. I want to edit status via admin. But others field, admin can't edit.. In this scenario can I write new view and template for admin or just customize the default admin panel? Sep 21, 2017 at 16:31
  • You need to restrict your admin panel for some users? So they can only edit some of fields?
    – Serjik
    Sep 21, 2017 at 16:33
  • You cannot do that in ordinary way, just a tricky way, define a new model class as proxy of your current class and do restriction on it, that give access to that instead of your primary model
    – Serjik
    Sep 21, 2017 at 16:38
  • Or you can just set fields in your current admin, but in that case, anyone else cannot edit extra fields
    – Serjik
    Sep 21, 2017 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.