title: How to create an instance of a model through foreign key
body: <p>I'm trying to find a way how to create or update an instance of a model through a foreign key.</p>
  
  <p>I have two models: Podcast and Guest which are connected via foreign key on <em>guest_name</em>. I'm using Youtube API to pull data from videos and regex to extract data needed for a set of fields in both models. I'm wondering if there to pass guest_name from Podcast model (which would be extracted via calculated filed in Podcast model) to Guest model and create or update (search via '<em>WHERE LIKE '%guest_name%'</em>) its instance on the creation of Podcast instance?</p>
  
  <p>Thank you for all the help</p>
  
  <pre><code>class Guest(models.Model):
      guest_name = models.CharField(max_length=30) #full name
      occupation = models.CharField(max_length=20)
      short_bio = models.TextField()
  
      def __str__(self):
          return self.guest_name
  
      def get_absolute_url(self):
          return reverse("roll:guest_detail", kwargs={'pk':self.pk})
  
  class Podcast(models.Model):
      category = models.CharField(max_length=255) # Needs to be a Dropdown
      date = models.DateTimeField(blank=True, null=True) #published date
      guest_name = models.ForeignKey(Guest, on_delete=models.CASCADE) # https://docs.djangoproject.com/en/2.2/topics/db/examples/many_to_one/
      synopsis = models.TextField()
      index = models.IntegerField(blank=True,null=True,unique=True)
      video = EmbedVideoField(help_text="Remove anything after the Video ID",blank=False)  # same like models.URLField()
      thumbnail_url = models.URLField(help_text="URL to the image",blank=True)
      # slug = models.SlugField(max_length=140, unique=True)
      # video_id = re.search('(\?v=)(.*)', self.video)
      # thumbnail = models.CharField(max_length=100,default="https://img.youtube.com/vi/{}/0.jpg".format(str(save(video))))
  
      @property
      def thumbnail(self):
          video_id = re.search('(\?v=)(.*)', self.video)
          return 'https://img.youtube.com/vi/{}/0.jpg'.format(video_id.group(2))
  
      @property
      def publishedAt(self):
          api_key = "XXXX"
          youtube = build('youtube','v3',developerKey=api_key)
          video_id = re.search('(\?v=)(.*)', self.video)
          request = youtube.videos().list(
                  part="snippet",
                  id=video_id.group(2)
                  )
          response = request.execute()
          dict = {}
          for x in response['items']:
              dict['published'] = x['snippet']['publishedAt']
  
          for z in dict.values():
              datetime_object = datetime.strptime(z, "%Y-%m-%dT%H:%M:%S.%fZ")
              date = datetime.date(datetime_object)
              return date
  
      @property
      def viewCount(self):
          api_key = "XXX"
          youtube = build('youtube','v3',developerKey=api_key)
          video_id = re.search('(\?v=)(.*)', self.video)
          request = youtube.videos().list(
                  part="snippet,statistics",
                  id=video_id.group(2)
                  )
          response = request.execute()
          return  format(int(response['items'][0]['statistics']['viewCount']), ',d')
  
      @property
      def get_index(self):
          api_key = "XXXX"
          youtube = build('youtube','v3',developerKey=api_key)
          video_id = re.search('(\?v=)(.*)', self.video)
          request = youtube.videos().list(
                  part="snippet,statistics",
                  id=video_id.group(2)
                  )
          response = request.execute()
          store = response['items'][0]['snippet']['title']
          xe = re.search("(\d{3,4})",store)
          return int(xe.group(1))
  
  
      def get_absolute_url(self):
          return reverse("roll:podcast_detail", kwargs={'pk':self.pk})
  
      def save(self, *args, **kwargs):
            self.date = self.publishedAt
            self.thumbnail_url = self.thumbnail
            self.index = self.get_index
            super().save(*args, **kwargs)
  </code></pre>