我想通过在Django用户个人资料(1.2.5,在Ubuntu整洁的提供的版本)的方式,一些额外的属性添加到用户,但每当我通过管理控制台创建新的用户,新的一个包含的属性(例如,'phone'),我得到一个"列user_id不是唯一的"IntegrityError.
我看到其他人遇到了这个问题,他们似乎通过在userprofile创建信号中添加一个独特的dispatch_uid来解决它,但这对我不起作用:
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
class UserProfile(models.Model):
user = models.OneToOneField(User)
phone = models.CharField(max_length=40,blank=True,null=True)
def create_user_profile(sender, instance, **kwargs):
UserProfile.objects.get_or_create(user=instance)
post_save.connect(create_user_profile, sender=User, dispatch_uid="users-profilecreation-signal")
Run Code Online (Sandbox Code Playgroud)
AUTH_PROFILE_MODULE设置为在settings.py中指向此类.
谁知道我做错了什么?
我正在使用python-zookeeper进行锁定,而我正试图找出一种方法来让执行等待通知,因为它正在观看文件,因为它zookeeper.exists()立即返回,而不是阻塞.
基本上,我有下面列出的代码,但我不确定实现notify()和wait_for_notification()函数的最佳方法.它可以用os.kill()和完成signal.pause(),但是我确信如果我以后在一个程序中有多个锁可能会导致问题 - 是否有一个特定的Python库对这类事情有好处?
def get_lock(zh):
lockfile = zookeeper.create(zh,lockdir + '/guid-lock-','lock', [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL | zookeeper.SEQUENCE)
while(True):
# this won't work for more than one waiting process, fix later
children = zookeeper.get_children(zh, lockdir)
if len(children) == 1 and children[0] == basename(lockfile):
return lockfile
# yeah, there's a problem here, I'll fix it later
for child in children:
if child < basename(lockfile):
break
# exists will call notify when the watched file …Run Code Online (Sandbox Code Playgroud) 我正试图从一个程序中启动Android网络共享设置菜单,但它是其名称中包含斜杠的半隐藏菜单之一(com.android.settings/.tether.Tether),我不知道是什么我应该把它称为.这是我到目前为止所尝试的:
Intent intent = new Intent();
intent.setClassName("com.android.settings", "com.android.settings/.tether.Tether");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
我还尝试了setClassName行中的"com.android.settings /"
然而,无论哪种方式,它说它找不到类:
I/ActivityManager(51):启动活动:Intent {act = android.intent.action.MAIN cmp = com.android.settings/com.android.settings/.tether.Tether} D/AndroidRuntime(254):关闭VM W/dalvikvm(254):threadid = 3:线程退出,未捕获异常(group = 0x4001b188)E/AndroidRuntime(254):未捕获处理程序:由于未捕获异常导致主线程退出E/AndroidRuntime(254):java.lang.RuntimeException :无法启动活动ComponentInfo {com.zzzz.launcher/com.zzzz.launcher.Launcher}:> android.content.ActivityNotFoundException:无法找到显式活动类> {com.android.settings/com.android.settings /. tether.Tether}; 你有没有在AndroidManifest.xml中声明这个活动?
我的清单文件中列出了以下活动:
<activity android:name="com.android.settings/.tether.Tether" />
Run Code Online (Sandbox Code Playgroud)
(而且我也尝试用反斜杠逃避斜线,那里)
似乎没有任何关联的Settings.*值与之关联,因此通常的启动方式如下所示,不起作用:
startActivity(new Intent(Settings.ACTION_TETHER_SETTINGS));
Run Code Online (Sandbox Code Playgroud)
...但即便如此,我仍然想学习如何使用它的类名启动它,因为其他类的名称中包含斜杠(例如com.android.settings./proxySelector)我想以类似的方式发射.
干杯,
保罗
(进一步的堆栈跟踪:)
I/ActivityManager(59):开始活动:Intent {act = android.intent.action.MAIN cat = [android.intent.category.LAUNCHER] flg = 0x10200000 cmp = com.zzzz.launcher/.ProxySet bnds = [163,240] [237,319]} I/ActivityManager(59):启动proc com.zzzz.launcher for activity com.zzzz.launcher/.ProxySet:pid = 397 uid = 10040 gids = {1015} I/ActivityManager(59):启动活动: Intent {cmp = com.android.settings/.ProxySelector} D/AndroidRuntime(397):关闭VM …