title: How to add a new record with a guest (anonymous) user in Django
body: <p>I am a beginner in Django and I am very need your help.</p>
  <p><em><strong>Part of code:</strong></em></p>
  <p>models.py</p>
  <pre><code>from django.contrib.auth.models import User
  
  class Author(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE)
      department = models.CharField(max_length=200)
  
      def __str__(self):
          return self.user.username
  
  class hardware(models.Model):
      hostname = socket.gethostname()
      login_username = getpass.getuser()
      user = User.username
  
      hardware_name = models.CharField(max_length=20)
      order_no = models.CharField(max_length=10)
      price = models.DecimalField(max_digits=5,decimal_places=2)
      confirm = models.BooleanField(default=False)
      login_user = models.ForeignKey(Author, on_delete=models.CASCADE)
      computer_login_user = models.CharField(max_length=10,default=login_username)
      computer = models.CharField(max_length=30,default=hostname)
  
  
      def __str__(self):
          return self.order_no
  </code></pre>
  <p>views.py</p>
  <pre><code>def get_author(user):
      qs = Author.objects.filter(user=user)
      if qs.exists():
          return qs[0]
      return None
  
  def new_record(request):
      form = OrderForm(request.POST or None, request.FILES or None)
      if form.is_valid():
          author = get_author(request.user)
          form.instance.login_user = author
          form.save()
          return redirect(all_records)
  
      context = {
          'form': form
      }
      return render(request, 'orders/form.html', context)
  </code></pre>
  <p><em><strong>I will try to explain my problem briefly.</strong></em></p>
  <p>Computers are in public places (productions) and anyone can add new record. That why in the table is info about hostname, who is login on computer and login user.</p>
  <p>So it works well when the user is logged in to the system, but there is a problem when a new record tries to add an unlogged user (guest). Is an error &quot;'AnonymousUser' object is not iterable&quot;.
  I know that <strong>request.user</strong> is empty now.</p>
  <p><em><strong>Ok, Now questions...</strong></em></p>
  <p>How to add &quot;guest&quot; user and add it if noone is login?? How to add a new record if the user is not logged in??</p>
  <p>I am sorry for very long post and Thanks for all suggestions.</p>