我不知道我是否得到了正确的名称,但是我想看看是否有一种特定的方法来实现一个文本字段,这样当它没有焦点并且是空的时候,一个微弱的灰色字符串文本显示在字段中.单击该字段时,文本应该消失,就像StackOverflow的搜索栏一样.我知道我可以改变使用setForeground()
并集中听众来实现这一点,但我只是想知道是否有人知道某些Java实现可以为我处理这个问题.
当我尝试manage.py makemigrations
在Django 1.7 上运行时,我收到以下错误:
ValueError: Cannot serialize: <bound method ModelBase.get_default of <class 'printapp.models.JobConfiguration'>>
There are some values Django cannot serialize into migration files.
For more, see https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing
Run Code Online (Sandbox Code Playgroud)
所以看起来get_default
定义的方法存在问题JobConfiguration
,其定义在下面重复:
@classmethod
def get_default(cls):
result = cls()
result.save()
return result
Run Code Online (Sandbox Code Playgroud)
按照错误消息中提供的链接,看起来序列化"类引用"是一个受支持的功能.
是一个"类引用"一样@classmethod
吗?
如何在"模块的顶级范围"中添加"类引用"?
为什么必须通过迁移跟踪方法?我假设迁移是针对数据库模式的,它只跟踪存储的数据类型,而不是类所使用的方法类型.
值得注意的是:将get_default
下面重复的静态方法的定义更改为解决问题,但代价是必须对JobConfiguration
类名进行硬编码.
@staticmethod
def get_default():
result = JobConfiguration()
result.save()
return result
Run Code Online (Sandbox Code Playgroud)
(某些上下文:此方法是JobConfiguration.get_default
从a中引用的models.OneToOneField(JobConfiguration, default=JobConfiguration.get_default)
,其效果是为每个创建的字段创建新的JobConfiguration.)
因此,我只安装了python解释器,并想使用help(sys)功能来获取有关sys模块的更多信息,但是我遇到了这个错误,不知道出了什么问题。
C:\Users\Jake>python
Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> help(sys)
'more' is not recognized as an internal or external command,
operable program or batch file.
>>>
Run Code Online (Sandbox Code Playgroud)
这是因为我的计算机上没有sys模块的源代码还是完全没有其他东西?任何帮助将不胜感激。