I have a ModelForm that creates an instance of a custom user (AbstractUser model). Whenever I try to submit the form, nothing happens except a reload of the page (because of the action), and nothing is getting saved in the database. The code is as following:
def sign_up(request):
if request.method == 'POST':
print("test")
form = UserForm(request.POST)
if form.is_valid():
form.save()
data = form.cleaned_data
user = authenticate(
username=data['username'],
password=data['password']
)
user_login(request, user)
else:
form = UserForm()
return render(request, 'schedules/signup/signup.html', {'form':form})
class ClientUser(AbstractUser):
classes = models.ManyToManyField(ScheduleClass)
personal_changes = models.TextField(name="personal_changes", default="none")
schedule = models.ManyToManyField(Schedule)
def get_classes(self):
return self.classes
class UserForm(forms.ModelForm):
class Meta:
model = ClientUser
fields = ['username', 'password', 'classes', 'schedule']
<form method="post" action="http://127.0.0.1:8000/">
{% csrf_token %}
{{ form }}
<input type="submit">
</form>
For some reason, it's also not even printing the line I wrote on line 3 of the sign_up
func, even when I post. Is there something I am doing wrong?