title: Default Value in ModelForm from Database
body: <p>I have a ModelForm in my Django App which should always display the latest given Option as default Input in the form but it's not working:</p>
  
  <p>models.py</p>
  
  <pre><code>from django.db import models
  
  Anmeldung = (
      ('1', 'Ja'),
      ('2', 'Nein'),
      ('3', 'Noch nicht entschieden'),
  )
  
  Essen = (
      ('1', 'Fleisch'),
      ('2', 'Fisch'),
      ('3', 'Vegetarisch'),
  )
  
  class Eintrag(models.Model):
      Name = models.CharField(max_length=200)
      Anmeldung = models.CharField(
          max_length=2,
          choices=Anmeldung,
          default=Eintrag.objects.filter(Name=request.user).Anmeldung # Thats not working
      Essen = models.CharField(
          max_length=2,
          choices=Essen,
          default=1)
      pub_date = models.DateTimeField('date published')
  </code></pre>
  
  <p>Only one row per user is in the data so that should not be a problem. 
  How do I achieve this? Is models.py even the right place or do I have to write this into the views or form part?</p>
  
  <p>forms.py and models.py if it helps:</p>
  
  <p>forms.py</p>
  
  <pre><code>from django import forms
  from .models import Eintrag
  
  class NameForm(forms.ModelForm):
  
      class Meta:
              model = Eintrag
              fields = ['Anmeldung', 'Essen']
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from django.shortcuts import render
  from django.utils import timezone
  from django.contrib.auth.decorators import login_required
  from django.http import HttpResponseRedirect
  
  from .forms import NameForm
  from .models import Eintrag
  
  @login_required()
  def get_name(request):
  
      # if this is a POST request we need to process the form data
      if request.method == 'POST':
          # create a form instance and populate it with data from the request:
          form = NameForm(request.POST)
          # check whether it's valid:
          if form.is_valid():
              Eintrag.objects.filter(Name=request.user).delete()
              eintrag = form.save(commit=False)
              # process the data in form.cleaned_data as required
              # ...
              # redirect to a new URL:
              eintrag.Name = request.user  # Set the user object here
              eintrag.pub_date = timezone.now()  # Set the user object here
              eintrag.save()
  
              return HttpResponseRedirect(request.path)  # generate an empty form
  
      # if a GET (or any other method) we'll create a blank form
      else:
          form = NameForm()
  
      posts = Eintrag.objects.filter(Name=request.user)
      return render(request, 'form/name.html', {'form': form, 'posts': posts})
  </code></pre>
  
  <p>Thanks for any suggestions!</p>