2014-05-07 40 views
0

我有一個奇怪的錯誤,我不明白。對於每一個用戶,我需要創建Customer對象:Django超級用戶沒有正確創建

@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 =假和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

爲什麼兩個電子郵件ids實際上用戶表有一個emailid –

+0

你刪除了所有表和syncdb –

+0

@SundarNataraj我需要第二封電子郵件,因爲這個客戶表可以單獨使用。是的,我刪除了數據庫,重新創建它,然後運行syncdb。 – NST

回答

0

好吧,從1.5切換到django 1.6.4版本後,我的原代碼開始工作。雖然我確定我以前有1.6版本。我如何切換到舊版本,當我不知道...

相關問題