我有一个奇怪的错误,我无法理解。对于每个用户,我需要创建Customer对象:
@receiver(post_save, sender = User)
def after_user_is_created(sender, instance, created, **kwargs):
if not instance.is_superuser:
if created:
customer = Customer(email = instance.email, status = Status.objects.get(status = "registered"), user = instance)
customer.save()
但是当我执行初始syncdb创建所有表并创建超级用户时,使用此代码创建为is_superuser = False和is_staff = False。
这是我的客户模型:
class Customer(models.Model):
name = models.CharField(max_length = 120, blank = True)
middlename = models.CharField(max_length = 120, blank = True)
surname = models.CharField(max_length = 120, blank = True)
email = models.EmailField(max_length = 254)
birthdate = models.DateField(blank = True, null = True)
status = models.ForeignKey(Status)
citizenships = models.ManyToManyField(Country, blank = True)
user = models.ForeignKey(User, blank = True, null = True)
我不明白我的代码有什么问题?
答案 0 :(得分:0)
好的,从1.5切换到django版本1.6.4后我的原始代码开始工作。虽然我确定之前有1.6版。我如何切换到旧版本,当我不知道...