Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Model Inheritance. Hiding or removing fields

I want to inherit a model class from some 3rd party code. I won't be using some of the fields but want my client to be able to edit the model in Admin. Is the best bet to hide them from Admin or can I actually prevent them being created in the first place?

Additionally - what can I do if one of the unwanted fields is required? My first thought is to override the save method and just put in a default value.

like image 511
Andy Baker Avatar asked Mar 04 '09 17:03

Andy Baker


2 Answers

You can control the fields that are editable in admin.

From the Django docs:

If you want a form for the Author model that includes only the name and title fields, you would specify fields or exclude like this:

class AuthorAdmin(admin.ModelAdmin):
    fields = ('name', 'title')

class AuthorAdmin(admin.ModelAdmin):
    exclude = ('birth_date',)

http://docs.djangoproject.com/en/dev/ref/contrib/admin/

like image 126
Harold Avatar answered Sep 27 '22 18:09

Harold


If you are inheriting the model then it is probably not wise to attempt to hide or disable any existing fields. The best thing you could probably do is exactly what you suggested: override save() and handle your logic in there.

like image 23
Andrew Hare Avatar answered Sep 27 '22 18:09

Andrew Hare