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)
-
How is build the model you want to adapt ? you should add it if you want efficient help.PRMoureu– PRMoureu2017年09月21日 16:24:54 +00:00Commented Sep 21, 2017 at 16:24
2 Answers 2
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.
Comments
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.