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)
asked Sep 21, 2017 at 16:22
1
  • How is build the model you want to adapt ? you should add it if you want efficient help. Commented 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.

answered Sep 21, 2017 at 16:55
Sign up to request clarification or add additional context in comments.

Comments

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.

answered Sep 21, 2017 at 16:26

4 Comments

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?
You need to restrict your admin panel for some users? So they can only edit some of fields?
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
Or you can just set fields in your current admin, but in that case, anyone else cannot edit extra fields

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.