Im try different method for user register. I want to enroll a company staff user: I want to register method "companyname.staffusername" but I cant do register. How can I do it? Im try different way but I have error.
I seen this error: "'str' object is not callable"
Forms:
from django import forms
from django.db.models import fields
from .models import SubUser
class SubUserForm(forms.ModelForm):
class Meta:
model = SubUser
fields = ["Subusername","Subpassword","active","staff","Company"]
Views:
from article.views import index
from user.views import loginUser
from django.contrib import messages
from django.contrib.auth import authenticate
from django.shortcuts import redirect, render
from . import forms
from .models import SubUser
# Create your views here.
def RegisterSubUser(request):
if request.method=="POST":
form = forms.SubUserForm(request.POST)
if form.is_valid():
username = form.cleaned_data.get("Subusername")
password = form.cleaned_data.get("Subpassword")
newUser = SubUser(Subusername = username)
newUser.Subpassword(password)
newUser.save()
loginUser(request,newUser)
messages.success(request,"Kayıt Başarılı")
messages.warning(request,"DANGER")
return render(request,"index.html")
context ={
"form":form
}
return render(request,"register.html",context)
else:
form = forms.SubUserForm()
context ={
"form":form
}
return render(request,"register.html",context)
Models:
from django.db import models
# Create your models here.
class SubUser(models.Model):
Subusername = models.CharField(max_length=15,verbose_name="kullanıcı adı")
Subpassword = models.CharField(max_length=15,verbose_name="Parola")
active = models.BooleanField(default=True)
staff = models.BooleanField(default=True)
Company = models.ForeignKey("auth.User", on_delete= models.CASCADE,verbose_name="Çalıştığı Firma")
def __str__(self):
return self.Subusername
I think you get the error at
newUser.Subpassword(password)
Should be
newUser.Subpassword=password
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.