AttributeError at /accounts/signup/ 'str' object has no attribute 'add'
Am new using django so i used practical example on this tutorial on extending user model using User Profile, am having trouble on form.py it gives that error, on removing this line;
supervisor.su_mobile_number.add(*self.cleaned_data.get('su_mobile_number'))
it works smoothly but no data for su_mobile_number was inserted o the database
view.py
class SupervisorSignUpView(CreateView):
model = User
form_class = SupervisorSignUpForm
template_name = 'registration/signup_form.html'
def get_context_data(self, **kwargs):
kwargs['user_type'] = 'supervisor'
return super().get_context_data(**kwargs)
def form_valid(self, form):
user = form.save()
login(self.request, user)
return redirect('home')
model.py
class User(AbstractUser):
is_supervisor = models.BooleanField(default=False)
is_student = models.BooleanField(default=False)
class Supervisor(models.Model):
user = models.OneToOneField('User', on_delete=models.CASCADE, primary_key=True, related_name='supervisor')
su_mobile_number = models.CharField(max_length=200)
forms.py
class SupervisorSignUpForm(UserCreationForm):
su_mobile_number = forms.CharField()
class Meta(UserCreationForm.Meta):
model = User
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user)
supervisor.su_mobile_number.add(*self.cleaned_data.get('su_mobile_number'))
return user
python django
add a comment |
Am new using django so i used practical example on this tutorial on extending user model using User Profile, am having trouble on form.py it gives that error, on removing this line;
supervisor.su_mobile_number.add(*self.cleaned_data.get('su_mobile_number'))
it works smoothly but no data for su_mobile_number was inserted o the database
view.py
class SupervisorSignUpView(CreateView):
model = User
form_class = SupervisorSignUpForm
template_name = 'registration/signup_form.html'
def get_context_data(self, **kwargs):
kwargs['user_type'] = 'supervisor'
return super().get_context_data(**kwargs)
def form_valid(self, form):
user = form.save()
login(self.request, user)
return redirect('home')
model.py
class User(AbstractUser):
is_supervisor = models.BooleanField(default=False)
is_student = models.BooleanField(default=False)
class Supervisor(models.Model):
user = models.OneToOneField('User', on_delete=models.CASCADE, primary_key=True, related_name='supervisor')
su_mobile_number = models.CharField(max_length=200)
forms.py
class SupervisorSignUpForm(UserCreationForm):
su_mobile_number = forms.CharField()
class Meta(UserCreationForm.Meta):
model = User
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user)
supervisor.su_mobile_number.add(*self.cleaned_data.get('su_mobile_number'))
return user
python django
su_mobile_number
field is aCharField
. What you are trying to do withsupervisor.su_mobile_number.add
?
– Abdul Niyas P M
Dec 31 '18 at 9:32
@AbdulNiyasPM, thanks for the reply, i want to save it to db after creating user associated with it
– japhary juma
Dec 31 '18 at 9:36
1
supervisor = Supervisor.objects.create(user=user, su_mobile_number=self.cleaned_data.get('su_mobile_number')))
??
– Abdul Niyas P M
Dec 31 '18 at 9:37
add a comment |
Am new using django so i used practical example on this tutorial on extending user model using User Profile, am having trouble on form.py it gives that error, on removing this line;
supervisor.su_mobile_number.add(*self.cleaned_data.get('su_mobile_number'))
it works smoothly but no data for su_mobile_number was inserted o the database
view.py
class SupervisorSignUpView(CreateView):
model = User
form_class = SupervisorSignUpForm
template_name = 'registration/signup_form.html'
def get_context_data(self, **kwargs):
kwargs['user_type'] = 'supervisor'
return super().get_context_data(**kwargs)
def form_valid(self, form):
user = form.save()
login(self.request, user)
return redirect('home')
model.py
class User(AbstractUser):
is_supervisor = models.BooleanField(default=False)
is_student = models.BooleanField(default=False)
class Supervisor(models.Model):
user = models.OneToOneField('User', on_delete=models.CASCADE, primary_key=True, related_name='supervisor')
su_mobile_number = models.CharField(max_length=200)
forms.py
class SupervisorSignUpForm(UserCreationForm):
su_mobile_number = forms.CharField()
class Meta(UserCreationForm.Meta):
model = User
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user)
supervisor.su_mobile_number.add(*self.cleaned_data.get('su_mobile_number'))
return user
python django
Am new using django so i used practical example on this tutorial on extending user model using User Profile, am having trouble on form.py it gives that error, on removing this line;
supervisor.su_mobile_number.add(*self.cleaned_data.get('su_mobile_number'))
it works smoothly but no data for su_mobile_number was inserted o the database
view.py
class SupervisorSignUpView(CreateView):
model = User
form_class = SupervisorSignUpForm
template_name = 'registration/signup_form.html'
def get_context_data(self, **kwargs):
kwargs['user_type'] = 'supervisor'
return super().get_context_data(**kwargs)
def form_valid(self, form):
user = form.save()
login(self.request, user)
return redirect('home')
model.py
class User(AbstractUser):
is_supervisor = models.BooleanField(default=False)
is_student = models.BooleanField(default=False)
class Supervisor(models.Model):
user = models.OneToOneField('User', on_delete=models.CASCADE, primary_key=True, related_name='supervisor')
su_mobile_number = models.CharField(max_length=200)
forms.py
class SupervisorSignUpForm(UserCreationForm):
su_mobile_number = forms.CharField()
class Meta(UserCreationForm.Meta):
model = User
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user)
supervisor.su_mobile_number.add(*self.cleaned_data.get('su_mobile_number'))
return user
python django
python django
edited Dec 31 '18 at 9:33
japhary juma
asked Dec 31 '18 at 9:30
japhary jumajaphary juma
3210
3210
su_mobile_number
field is aCharField
. What you are trying to do withsupervisor.su_mobile_number.add
?
– Abdul Niyas P M
Dec 31 '18 at 9:32
@AbdulNiyasPM, thanks for the reply, i want to save it to db after creating user associated with it
– japhary juma
Dec 31 '18 at 9:36
1
supervisor = Supervisor.objects.create(user=user, su_mobile_number=self.cleaned_data.get('su_mobile_number')))
??
– Abdul Niyas P M
Dec 31 '18 at 9:37
add a comment |
su_mobile_number
field is aCharField
. What you are trying to do withsupervisor.su_mobile_number.add
?
– Abdul Niyas P M
Dec 31 '18 at 9:32
@AbdulNiyasPM, thanks for the reply, i want to save it to db after creating user associated with it
– japhary juma
Dec 31 '18 at 9:36
1
supervisor = Supervisor.objects.create(user=user, su_mobile_number=self.cleaned_data.get('su_mobile_number')))
??
– Abdul Niyas P M
Dec 31 '18 at 9:37
su_mobile_number
field is a CharField
. What you are trying to do with supervisor.su_mobile_number.add
?– Abdul Niyas P M
Dec 31 '18 at 9:32
su_mobile_number
field is a CharField
. What you are trying to do with supervisor.su_mobile_number.add
?– Abdul Niyas P M
Dec 31 '18 at 9:32
@AbdulNiyasPM, thanks for the reply, i want to save it to db after creating user associated with it
– japhary juma
Dec 31 '18 at 9:36
@AbdulNiyasPM, thanks for the reply, i want to save it to db after creating user associated with it
– japhary juma
Dec 31 '18 at 9:36
1
1
supervisor = Supervisor.objects.create(user=user, su_mobile_number=self.cleaned_data.get('su_mobile_number')))
??– Abdul Niyas P M
Dec 31 '18 at 9:37
supervisor = Supervisor.objects.create(user=user, su_mobile_number=self.cleaned_data.get('su_mobile_number')))
??– Abdul Niyas P M
Dec 31 '18 at 9:37
add a comment |
1 Answer
1
active
oldest
votes
Use =
operator to assign value and then call save()
method
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user)
supervisor.su_mobile_number = self.cleaned_data.get('su_mobile_number')
supervisor.save()
return user
more shorter way is (as @Abdul Niyas P M mentioned)
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user, su_mobile_number=self.cleaned_data.get('su_mobile_number'))
return user
let me try it, i will getb back to you, thanks
– japhary juma
Dec 31 '18 at 9:45
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985793%2fattributeerror-at-accounts-signup-str-object-has-no-attribute-add%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use =
operator to assign value and then call save()
method
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user)
supervisor.su_mobile_number = self.cleaned_data.get('su_mobile_number')
supervisor.save()
return user
more shorter way is (as @Abdul Niyas P M mentioned)
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user, su_mobile_number=self.cleaned_data.get('su_mobile_number'))
return user
let me try it, i will getb back to you, thanks
– japhary juma
Dec 31 '18 at 9:45
add a comment |
Use =
operator to assign value and then call save()
method
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user)
supervisor.su_mobile_number = self.cleaned_data.get('su_mobile_number')
supervisor.save()
return user
more shorter way is (as @Abdul Niyas P M mentioned)
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user, su_mobile_number=self.cleaned_data.get('su_mobile_number'))
return user
let me try it, i will getb back to you, thanks
– japhary juma
Dec 31 '18 at 9:45
add a comment |
Use =
operator to assign value and then call save()
method
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user)
supervisor.su_mobile_number = self.cleaned_data.get('su_mobile_number')
supervisor.save()
return user
more shorter way is (as @Abdul Niyas P M mentioned)
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user, su_mobile_number=self.cleaned_data.get('su_mobile_number'))
return user
Use =
operator to assign value and then call save()
method
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user)
supervisor.su_mobile_number = self.cleaned_data.get('su_mobile_number')
supervisor.save()
return user
more shorter way is (as @Abdul Niyas P M mentioned)
@transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_supervisor = True
user.save()
supervisor = Supervisor.objects.create(user=user, su_mobile_number=self.cleaned_data.get('su_mobile_number'))
return user
answered Dec 31 '18 at 9:38
JPGJPG
13.7k2832
13.7k2832
let me try it, i will getb back to you, thanks
– japhary juma
Dec 31 '18 at 9:45
add a comment |
let me try it, i will getb back to you, thanks
– japhary juma
Dec 31 '18 at 9:45
let me try it, i will getb back to you, thanks
– japhary juma
Dec 31 '18 at 9:45
let me try it, i will getb back to you, thanks
– japhary juma
Dec 31 '18 at 9:45
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53985793%2fattributeerror-at-accounts-signup-str-object-has-no-attribute-add%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
su_mobile_number
field is aCharField
. What you are trying to do withsupervisor.su_mobile_number.add
?– Abdul Niyas P M
Dec 31 '18 at 9:32
@AbdulNiyasPM, thanks for the reply, i want to save it to db after creating user associated with it
– japhary juma
Dec 31 '18 at 9:36
1
supervisor = Supervisor.objects.create(user=user, su_mobile_number=self.cleaned_data.get('su_mobile_number')))
??– Abdul Niyas P M
Dec 31 '18 at 9:37