how to make a user registration form including a model field in it as a 
required field?

like i want 

field to show up on registration page as a drop-down menu


class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    college = models.ForeignKey(College, on_delete=models.CASCADE)

@receiver(post_save, sender=User)
def update_user_profile(sender, instance, created, **kwargs):
    if created:

class College(models.Model):
    col = models.CharField(max_length=100)

    def __str__(self):
        return self.col


class UserForm(UserCreationForm):
    col = College.objects.all()
    password1 = forms.CharField(widget=forms.PasswordInput)
    password2 = forms.CharField(widget=forms.PasswordInput)
    college = forms.ChoiceField(widget=forms.Select(choices=col))

class Meta:
    model = User
    fields = ('username', 'college', 'password1', 'password2',)

and the includes this:

def signup(request):
if request.method == 'POST':
    form = SignUpForm(request.POST)
    if form.is_valid():
        user =
        raw_password = form.cleaned_data.get('password1')
        user = authenticate(username=user.username, password=raw_password)
        login(request, user)
        return redirect('home')
    form = SignUpForm()
return render(request, 'registration_form.html', {'form': form})

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

Reply via email to