Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Django Admin Custom list field label

Tags:

django-admin

How to change in_stock verbose_name ?

Models.py

class Book(models.Model):  name = models.CharField(u"Нэр", max_length = 200)   @property  def in_stock(self):   return self.stocks.count() 

Im Admin.py

class BookAdmin(admin.ModelAdmin):  list_display  = ('name', 'in_stock')  search_fields = ('name', ) 
like image 672
Ankhaa Avatar asked Nov 10 '10 05:11

Ankhaa


People also ask

What is Admin ModelAdmin in Django?

One of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site. The admin's recommended use is limited to an organization's internal management tool.

How do you make a field non editable in Django admin?

editable=False will make the field disappear from all forms including admin and ModelForm i.e., it can not be edited using any form. The field will not be displayed in the admin or any other ModelForm.

How can I remove extra's from Django admin panel?

Take a look at the Model Meta in the django documentation. Within a Model you can add class Meta this allows additional options for your model which handles things like singular and plural naming. Show activity on this post. inside model.py or inside your customized model file add class meta within a Model Class.


1 Answers

I guess you should use short_description attribute. Django-admin

def in_stock(self):   return self.stocks.count() in_stock.short_description = 'Your label here' 
like image 55
jargalan Avatar answered Dec 06 '22 05:12

jargalan