title: Django: create object from CSV that has a ForeignKey
body: <p>I've 2 models: <code>Category</code> and <code>Product</code>, and I need to upload both from CSVs files.</p>
  
  <p>I can do that when uploading CSV data for the <code>Category</code> model, as it does not have a ForeignKey field. </p>
  
  <p>But I get an error when trying to upload data from a CSV fro the <code>Product</code> model. As it has a ForeignKey to the Category model.</p>
  
  <blockquote>
    <p>ValueError: Cannot assign "'Stickers'": "Product.category" must be a
    "Category" instance.</p>
  </blockquote>
  
  <p>Is it possible? I could leave the field as blank and not requeried to do this manually later, but woudl be ideal to do this automatically.</p>
  
  <p><strong>commands/products.py</strong>:</p>
  
  <pre><code>import pandas as pd
  import csv
  from shop.models import Product
  from django.core.management.base import BaseCommand
  
  
  tmp_data_products=pd.read_csv('static/data/products.csv',sep=',', encoding="utf-8").fillna(" ")
  
  
  class Command(BaseCommand):
      def handle(self, **options):
          products = [
              Product(
                  category=row['category'],
                  product=row['product'],
                  slug=row['slug'],
                  description=row['description'],
                  size=row['size'],
                  quantity =row['quantity'],
                  price=row['image'],
                  available=row['available']
          )
              for _, row in tmp_data_products.iterrows()
          ]
  
          Product.objects.bulk_create(products)
  </code></pre>
  
  <p><strong>models.py:</strong></p>
  
  <pre><code>class Category(models.Model):
      category = models.CharField(max_length=250, unique=True)
      slug = models.SlugField(max_length=250, unique=True)
      description = models.TextField(blank=True, null=True)
      image = models.ImageField(upload_to='category', blank=True, null=True)
      video = EmbedVideoField(null=True, blank=True)
  
  class Product(models.Model):
      product = models.CharField(max_length=250, unique=True)
      slug = models.SlugField(max_length=250, unique=True)
      description = models.TextField(blank=True)
      category = models.ForeignKey(Category, on_delete=models.CASCADE)
      size = models.CharField(max_length=20, choices=TAMANIOS)
      quantity = models.CharField(max_length=20, choices=CANTIDADES)
      price = models.DecimalField(max_digits=10, decimal_places=2)
      image = models.ImageField(upload_to='product', blank=True, null=True)
      available = models.BooleanField(default=True)
      created = models.DateTimeField(auto_now_add=True)
      updated = models.DateTimeField(auto_now=True)
  </code></pre>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p><strong>categories.csv</strong></p>
  
  <pre><code>| category  | slug      | description                                                          | image | video |
  |-----------|-----------|----------------------------------------------------------------------|-------|-------|
  | Imantados | imantados | Los mejores imantados en vinyl,   acabado mate. Resistentes al agua. |       |       |
  | Stickers  | stickers  | Los mejores stickers en vinyl,   acabado mate. Resistentes al agua.  |       |       |
  | Muestras  | muestras  | Los mejores stickers en vinyl,   acabado mate. Resistentes al agua.  |       |       |
  </code></pre>
  
  <p><strong>products.csv</strong></p>
  
  <pre><code>| category | product                | slug                   | description                                                           | size      | quantity | price | image | available |
  |----------|------------------------|------------------------|-----------------------------------------------------------------------|-----------|----------|-------|-------|-----------|
  | Stickers | Stickers transparentes | stickers-transparentes | Stickers Transparentes en Vinyl de alta calidad. Resistentes al agua. | 5cm x 5cm | 50       | 50    |       | True      |
  | Stickers | Stickers transparentes | stickers-transparentes | Stickers Transparentes en Vinyl de alta calidad. Resistentes al agua. | 5cm x 5cm | 100      | 70    |       | True      |
  | Stickers | Stickers transparentes | stickers-transparentes | Stickers Transparentes en Vinyl de alta calidad. Resistentes al agua. | 5cm x 5cm | 200      | 90    |       | True      |
  | Stickers | Stickers transparentes | stickers-transparentes | Stickers Transparentes en Vinyl de alta calidad. Resistentes al agua. | 5cm x 5cm | 300      | 120   |       | True      |
  | Stickers | Stickers transparentes | stickers-transparentes | Stickers Transparentes en Vinyl de alta calidad. Resistentes al agua. | 5cm x 5cm | 500      | 140   |       | True      |
  | Stickers | Stickers transparentes | stickers-transparentes | Stickers Transparentes en Vinyl de alta calidad. Resistentes al agua. | 5cm x 5cm | 1000     | 200   |       | True      |
  | Stickers | Stickers transparentes | stickers-transparentes | Stickers Transparentes en Vinyl de alta calidad. Resistentes al agua. | 5cm x 5cm | 2000     | 300   |       | True      |
  | Stickers | Stickers transparentes | stickers-transparentes | Stickers Transparentes en Vinyl de alta calidad. Resistentes al agua. | 7cm x 7cm | 50       | 70    |       | True      |
  | Stickers | Stickers transparentes | stickers-transparentes | Stickers Transparentes en Vinyl de alta calidad. Resistentes al agua. | 7cm x 7cm | 100      | 90    |       | True      |
  | Stickers | Stickers transparentes | stickers-transparentes | Stickers Transparentes en Vinyl de alta calidad. Resistentes al agua. | 7cm x 7cm | 200      | 130   |       | True      |
  </code></pre>