相关疑难解决方法(0)

Python:删除子类中的类属性

我有一个子类,我希望它包含基类上存在的类属性.

我试过这个,但它不起作用:

>>> class A(object):
...     x = 5
>>> class B(A):
...     del x
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    class B(A):
  File "<pyshell#1>", line 2, in B
    del x
NameError: name 'x' is not defined
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

python inheritance namespaces class

40
推荐指数
6
解决办法
2万
查看次数

Django模型继承.隐藏或删除字段

我想从一些第三方代码继承一个模型类.我不会使用某些字段,但希望我的客户能够在Admin中编辑模型.最好的办法是将它们隐藏在管理员中,还是我真的可以防止它们首先被创建?

另外 - 如果需要其中一个不需要的字段,我该怎么办?我的第一个想法是覆盖save方法,只需输入默认值.

python django django-models django-admin

10
推荐指数
2
解决办法
4790
查看次数