I am using some subclasses in my Django app, and I continue the logic through my administrator implementation I am
At present, I have this administrator fixed:
class StellarObjectAdmin (admin.ModelAdmin): list_display = ('title', 'created_at', 'created_by', 'Updated_at', 'updated_by) Now, I have a planet square, which is the subclass of StellarObject, with an additional area. I want to add this field to list_disk (not completely replacing the StellarObject's display).
If I try to do something like this:
class PlanetAdmin (StellarObjectAdmin): list_display.insert (1, 'size')< / Pre>I get the following error:
name 'list_display' is not definedI will accept, I am very new to the dragon I am in general, and in general, I am sure that I am reminded of some simplicity.
Thanks
You will need to use:
StellarObjectAdmin.list_display.insert (1, 'size') In addition, you list to tuple (which ); list_display will need to change>. Example: list_display = [...] .
Finally, you might be surprised at what: by putting items, you are changing the list StellarObjectAdmin what you might want to do:
list_display = list (StellarObjectAdmin.list_display) # Copy the list list _display.insert (1, 'size') that your PlanetAdmin Will create a new copy of the list for the category.
This is because Python receives the heritage In fact, Python does not inject names into a namespace (for example, some languages have a magic in the form of this "variable" is injected, while Python is clearly equivalent to you - self - as the first argument of methods), and since class only another name If there is a place, then nothing (like, in its super squares) take it inside Or.
When you got 'a class, b , which comes from another class, a , and you B - the namespace, and so on. BFU - it first checks to see that the name of the B in foo Is, and if it is not, then it goes to check
I hope that it is clear ... if not, then I can clarify (or attempt to find relevant documents).
Comments
Post a Comment