title: Dynamic initial form data
body: <p>I am attempting to add a button to the customer's page to add a new device but when rendering the form I would like to pass the customer's name as an initial value.</p>
  <p>This was my personal Christmas project to make my work projects a bit more centralized in 2021.
  Im almost over the finish line but I've hit this bump. Any help would be appreciated.
  Thanks.</p>
  <p>I have two models in separate apps.</p>
  <pre><code>class Customer(models.Model):
      nameF = models.CharField(&quot;First Name&quot;, max_length=255, blank = True, null = True)
      nameL = models.CharField(&quot;Last Name&quot;, max_length=255, blank = True, null = True)
      nameN = models.CharField(&quot;Nickname&quot;, max_length=255, blank = True, null = True)
      address = models.CharField(&quot;Address&quot;, max_length=255, blank = True, null = True)
      phone = models.CharField(&quot;Phone&quot;, max_length=255, blank = True, null = True)
      email = models.EmailField(&quot;Email&quot;, max_length=254, blank = True, null = True)
      dateC = models.DateTimeField(&quot;Date Created&quot;, auto_now_add=True)
      dateU = models.DateTimeField(&quot;Last Updated&quot;, auto_now=True)
      note = models.TextField(&quot;Notes&quot;,  blank = True, null = True)
      def __str__(self):
          return self.nameF
      def get_absolute_url(self):
          return reverse (&quot;cfull&quot;, kwargs={&quot;pk&quot;: self.id})
  </code></pre>
  <p>and</p>
  <pre><code>class Device(models.Model):
  
      CONNECTION = (
          ('Local', 'Local'),
          ('IP/DOMAIN', 'IP/DOMAIN'),
          ('P2P', 'P2P')
      )
      TYPE = (
          ('DVR', 'DVR'),
          ('NVR', 'NVR'),
          ('Router', 'Router'),
          ('WLAN Controller', 'WLAN Controller'),
          ('AP', 'AP'),
          ('Doorbell', 'Doorbell'),
          ('Audio Controller', 'Audio Controller'),
          ('Other', 'Other')
  
      )
      BRAND = (
          ('HikVision', 'HikVision'),
          ('Dahua', 'Dahua'),
          ('Luxul', 'Luxul'),
          ('Trendnet', 'Trendnet'),
          ('Russound', 'Russound'),
          ('Ring', 'Ring'),
          ('Other', 'Other')
      )
      customer = models.ForeignKey('customer.Customer', null = True, on_delete=models.SET_NULL)
      alias = models.CharField(&quot;Alias&quot;, max_length=255, blank = True, null = True)
      dbrand = models.CharField(&quot;Brand&quot;, max_length=255, null = True, blank = True, choices=BRAND)
      dtype = models.CharField(&quot;Device Type&quot;, max_length=255, null = True, blank = True, choices=TYPE)
      connection = models.CharField(&quot;Remote Protocol&quot;, max_length=255, null = True, blank = True, choices=CONNECTION)
      localaddr = models.CharField(&quot;Local IP&quot;, max_length=255, blank = True, null = True)
      hostname = models.CharField(&quot;Hostname/IP&quot;, max_length=255, blank = True, null = True)
      username = models.CharField(&quot;Username&quot;, max_length=255, blank = True, null = True)
      password = models.CharField(&quot;Password&quot;, max_length=255, blank = True, null = True)
      model = models.CharField(&quot;Model Number&quot;, max_length=255, blank = True, null = True)
      serial = models.CharField(&quot;Serial Number&quot;, max_length=255, blank = True, null = True)
      dateU = models.DateTimeField(&quot;Date Uploaded&quot;, auto_now_add=True)
      note = models.TextField(&quot;Notes&quot;,  blank = True, null = True)
      def __str__(self):
          return self.alias
      def get_absolute_url(self):
          return reverse (&quot;dfull&quot;, kwargs={&quot;pk&quot;: self.id})
  </code></pre>
  <p>In my project, the individual customer pages are populated with a list of each customer's devices.</p>
  <pre><code>def CustomerDetailView(request, pk):
      customer = Customer.objects.get(id=pk)
      devices = customer.device_set.all()
      context = {'object':customer, 'devices':devices}
      return render(request, 'customer/cfull.html', context)
  </code></pre>
  <p>This is some HTML for the customer's page.</p>
  <pre><code>   &lt;hr&gt;
  &lt;div class=&quot;card-header&quot;&gt;
      &lt;h2 class=&quot;card-title text-center&quot;&gt;Customer Options&lt;/h2&gt;
  &lt;/div&gt;
  &lt;div class=&quot;card card-body&quot;&gt;
      &lt;a href=&quot;&quot; class=&quot;btn btn-primary btn-lg btn-block&quot;&gt;Add Device&lt;/a&gt;
      &lt;a href=&quot;{% url 'cedit' object.id %}&quot; class=&quot;btn btn-secondary btn-lg btn-block&quot;&gt;Edit Customer&lt;/a&gt;
      &lt;a href=&quot;{% url 'cdelete' object.id %}&quot; class=&quot;btn btn-danger btn-lg btn-block&quot;&gt;Delete Customer&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>