python class attribute inheritance

class, django, inheritance, python

Solution

Inheritance applies after the class's body executes. In the class body, you can use `lgrAdminObject.fields` -- you sure you want to alter the superclass's attribute rather than making a copy of it first, though? Seems peculiar... I'd start with a copy:

class Photos(lgrAdminObject):
    fields = list(lgrAdminObject.fields)

before continuing with alterations.

Problem

I am trying to save myself a bit of typing by writing the following code, but it seems I can't do this: ``` class lgrAdminObject(admin.ModelAdmin): fields = ["title","owner"] list_display = ["title","origin","approved", "sendToFrames"] class Photos(lgrAdminObject): fields.extend(["albums"]) ``` why doesn't that work? Also since they're not functions, I can't do the super trick ``` fields = super(Photos, self).fields fields.extend(["albums"]) ```

Original source