title: Create and UpdateView with foreign key related model in Django CBV
body: <p>I got 1 app "portfolio" with 2 models, the 2nd one has a FK with first and I need (create and update) view of that. I have the complete CRUD for the first model but I no have idea to get the same result with fk model. I'm looking for a create and update view with both. But I can't get access for proyects in a album form, so in that way for choosing the FK from projects to get related album to one of all projects created</p>
  
  <p><strong><em>models.py</em></strong></p>
  
  <pre><code>from django.db import models
  from django.contrib.auth.models import User
  from ckeditor.fields import RichTextField
  
  # Create your models here.
  
  class Project(models.Model):
      user = models.ForeignKey(User, on_delete = models.CASCADE, default=1)
      name = models.CharField(verbose_name='Nombre del proyecto', max_length=200)
      client = models.CharField(verbose_name='Nombre del cliente', max_length=200)
      description = RichTextField(verbose_name='Descripción')
      start = models.DateField(verbose_name='Fecha de Inicio', null=True, blank=True)
      ending = models.DateField(verbose_name='Fecha de Finalización', null=True, blank=True)
      order = models.SmallIntegerField(verbose_name="Orden", default=0)
      created = models.DateTimeField(verbose_name='Fecha de creación', auto_now_add=True)
      updated = models.DateTimeField(verbose_name='Fecha de modificación', auto_now=True)
  
      class Meta:
          verbose_name = 'Proyecto'
          verbose_name_plural = 'Proyectos'
          ordering = ['-start', 'order']
  
      def __str__(self):
          return self.name
  
  class Album(models.Model):
      project = models.ForeignKey(Project, on_delete = models.CASCADE)
      title = models.CharField(verbose_name='Título de la imagen', max_length=200, null=True, blank=True)
      image = models.ImageField(verbose_name='Imagen', upload_to='portfolio')
      created = models.DateTimeField(verbose_name='Fecha de creación', auto_now_add=True)
      updated = models.DateTimeField(verbose_name='Fecha de modificación', auto_now=True)
  
      class Meta:
          verbose_name = 'Imagen en el album'
          verbose_name_plural = 'Imágenes en el album'
          ordering = ['created']
  
          def __str__(self):
              return self.title
  </code></pre>
  
  <p><strong><em>views.py</em></strong></p>
  
  <pre><code>@method_decorator(staff_member_required(login_url='login'), name='dispatch')
  class ProjectCreateView(CreateView):
      model = Project
      template_name = "core/project_create_form.html"
      form_class = ProjectCreateForm
      success_url = reverse_lazy('home')
  
  @method_decorator(staff_member_required(login_url='login'), name='dispatch')
  class ProjectUpdateView(UpdateView):
      model = Project
      template_name = "core/project_update_form.html"
      form_class = ProjectUpdateForm
  
  
  @method_decorator(staff_member_required(login_url='login'), name='dispatch')
  class ProjectDeleteView(DeleteView):
      model = Project
      template_name = "core/project_delete_form.html"
      success_url = reverse_lazy('home')
  </code></pre>
  
  <p><strong><em>forms.py</em></strong></p>
  
  <pre><code>class ProjectCreateForm(forms.ModelForm):
  
      template_name = 'core/project_create_form.html'
  
      class Meta:
          model = Project
          fields = [
              'name',
              'client',
              'description',
              'start',
              'ending',
              'order',
              ]
  
          widgets = {
  
              'name':forms.TextInput(
                  attrs={
                      'class':'form-control'}),
  
              'client':forms.TextInput(
                  attrs={
                      'class':'form-control'}),
  
              'description':forms.Textarea(
                  attrs={
                      'class':'form-control'}),
  
              'start':forms.DateInput(
                  attrs={
                      'class':'form-control'}),
  
              'ending':forms.DateInput(
                  attrs={
                      'class':'form-control'}),
  
              'order':forms.NumberInput(
                  attrs={
                      'class':'form-control'}),
          }
  
  
  class ProjectUpdateForm(forms.ModelForm):
  
      template_name = 'core/project_update_form.html'
  
      class Meta:
          model = Project
          fields = [
              'name',
              'client',
              'description',
              'start',
              'ending',
              'order',
              ]
  
          widgets = {
  
              'name':forms.TextInput(
                  attrs={
                      'class':'form-control'}),
  
              'client':forms.TextInput(
                  attrs={
                      'class':'form-control'}),
  
              'description':forms.Textarea(
                  attrs={
                      'class':'form-control'}),
  
              'start':forms.DateInput(
                  attrs={
                      'class':'form-control'}),
  
              'ending':forms.DateInput(
                  attrs={
                      'class':'form-control'}),
  
              'order':forms.NumberInput(
                  attrs={
                      'class':'form-control'}),
          }
  </code></pre>