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.
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>