I think the problem here is that when you create the superuser, the related 
field will not be created.
You should add sistema = models.ForeignKey('Sistema', null=True) or sistema 
= models.ForeignKey('Sistema', default=1) where 1 is a placeholder 
'Sistema' object that you have created.
I suggest to just use the null method as it designs a better system.

On Thursday, November 7, 2013 2:56:03 PM UTC+1, Vanni Brutto wrote:
>
> i'm trying to use AbstractBaseUser to extend the user model...
>
> i used the code found on django pages, the only difference is that i use a 
> foreignkey to "Sistema" models.
> The originale code is on django pages: 
> https://docs.djangoproject.com/en/dev/topics/auth/customizing/
>
> my changes was:
>
> [...]
> class Sistema(models.Model):
>     models.ForeignKey(settings.AUTH_USER_MODEL)
>     nome = models.CharField(max_length=80)
>     def __unicode__(self):
>         return self.nome
>     class Meta:
>         verbose_name_plural = "Sistemi"
>
> [...]
>
> class MyUser(AbstractBaseUser):
>     email = models.EmailField(
>         verbose_name='email address',
>         max_length=255,
>         unique=True,
>         db_index=True,
>     )
>     date_of_birth = models.DateField()
>     is_active = models.BooleanField(default=True)
>     is_admin = models.BooleanField(default=False)
>
>     TIPO_CHOICES = (
>         ('C', 'Cameriere'),
>         ('G', 'Guest'),
>         ('A', 'Admin'),
>     )
>     tipo = models.CharField(max_length=1, choices=TIPO_CHOICES, 
> default="C")
>     sistema = models.ForeignKey(Sistema)
>
>
>
> when create the db with syncdb i got:
> ds\createsuperuser.py", line 116, in handle
>     user_data[field_name] = field.clean(raw_value, None)
>   File 
> "C:\apps\Python27\Lib\site-packages\django\db\models\fields\__init__.py",
>  line 255, in clean
>     self.validate(value, model_instance)
>   File 
> "C:\apps\Python27\Lib\site-packages\django\db\models\fields\related.py",
> line 1189, in validate
>     using = router.db_for_read(model_instance.__class__, 
> instance=model_instance
> )
>   File "C:\apps\Python27\Lib\site-packages\django\db\utils.py", line 250, 
> in _ro
> ute_db
>     return hints['instance']._state.db or DEFAULT_DB_ALIAS
> AttributeError: 'NoneType' object has no attribute '_state'
>
> C:\apps\xampp\htdocs\py\comanda>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cbf65546-3816-4140-93dd-29dc4ca9c728%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to