python - Creating a new instance of a Custom User Model in Django -
i have model extension of user model in django 1.8. connecting mysql database this.
class libraryuser(models.model): user_id = models.onetoonefield(user) is_catalogue_subscriber = models.booleanfield(default=true) is_research_subscriber = models.booleanfield(default=true) library_membership_number = models.charfield(max_length=64)
the reason why extended user
model, of course use authentication framework.
so now, want create new libraryuser using library_membership_number
login username. how should so? create user
first reference libraryuser
?
ie given some_
variables either received post
or migration of users new table
u = user.objects.create_user(email=some_email, password=some_password) lu = libraryuser(library_membership_number, user_id = u.id) lu.save()
or there correct way this? tried finding online can't find particularly address problem.
you should assign value specify fields following:
lu = libraryuser(library_membership_number= '...', user_id = user) lu.save()
library_membership_number
you can't assign variable
library_membership_number
.model
object containing fields. should appoint field , assign it:library_membership_number= '...'
, ormodel
can't parse field store.user_id
it has defined
foreignkey
in advance. can acceptmodel
object store:user_id = user
. don't call attribute ofuser
store inlibraryuser
.
Comments
Post a Comment