Carlos Futino
Carlos Futino

Reputation: 21

Django labels for custom admin fields on inline

I'm new both here and to Django, and I have a doubt about custom fields: I'm using custom models in my admin, but I would like to change the label that shows on the tabular inline.

My model is like this:

ModelA(Model):
    name = Model.charField(80)
    (...)

ModelB(Model):
    modelA = ModelA
    (...)

then in my admin I use:

def name_modelA(self):
    return ("%s" % self.modelA.name)

class ModelBInlne(TabularInline):
    (...)
    fields=('field1','field2',...,name_modelA)
    (...)

thing is, on the admin page the label for the name comes out "name_modelA", I'd like to change it to "name". Is it possible?

Hope I was clear enough.

Upvotes: 2

Views: 2001

Answers (1)

jro
jro

Reputation: 9474

I guess you will get what you want with verbose field names? That controls the label for editable fields in the admin interface.

For the tabular interface, I'd say something along the following lines should do:

class ModelAInline(TabularInline):
    model = ModelA

class ModelAAdmin(ModelAdmin):
    inlines = [ ModelAInline, ]

This makes your ModelA editable inline. I'm not exactly sure how you would like to have it displayed in your ModelB, but perhaps you could look through the ModelAdmin docs and use something from there?

Upvotes: 1

Related Questions