title: How to register with Django admin approval?
body: <p>In the system I created with Django, users should not log in without the admin approval after registration. For example, after the user fills in the registration form, user will see the warning</p>
  <blockquote>
  <p>waiting for admin approval</p>
  </blockquote>
  <p>and cannot login to the system without approval from the admin panel.</p>
  <p><em>views.py</em></p>
  <pre><code>def signup(request):
  
      form_class = SignUpForm
      if request.method == 'POST':
          form = SignUpForm(request.POST)
          if form.is_valid():
              user = form.save()
              user.refresh_from_db()  # load the profile instance created by the signal
              user.save()
              raw_password = form.cleaned_data.get('password1')
              user = authenticate(username=user.username, password=raw_password)
              user.first_name = form.data['first_name']
              user.last_name = form.data['last_name']
              user.rank = form.data['rank']
              user.comp_name = form.data['comp_name']
              login(request, user)
              return redirect('/')
      else:
          form = form_class()
      return render(request, 'signup.html', {'form': form})
  </code></pre>
  <p><em>models.py</em></p>
  <pre><code>class UserProfile(AbstractUser):
      ranks = (
          ('analyst', 'Analyst'),
          ...
      )
      comp_name = models.CharField(max_length=200, default=&quot;Choose&quot;)
      user_id = models.UUIDField(default=uuid.uuid4(), editable=False, unique=True)
      username = models.CharField(max_length=500, unique=True)
      first_name = models.CharField(max_length=200)
      last_name = models.CharField(max_length=200)
      password = models.CharField(max_length=50)
      email = models.EmailField(max_length=254)
      rank = models.CharField(max_length=200, choices=ranks)
  </code></pre>