title: Django generate bar code and save into image field
body: <p>I am able to generate the bar code and can save the image file in the root folder using this library <a href="https://pypi.org/project/python-barcode/" rel="nofollow noreferrer">python-barcode</a>.
  Now I am trying to generate the bar code image and save into the django image filed.</p>
  
  <p>Tryouts:</p>
  
  <pre><code>import barcode
  
  bc = Barcode.objects.latest('id')
  
  upc = barcode.get('upc', '123456789102', writer=ImageWriter())
  img = upc.render()  # Returns PIL image class
  # &lt;PIL.Image.Image image mode=RGB size=523x280 at 0x7FAE2B471320&gt;
  bc.img = img
  bc.save()
  </code></pre>
  
  <p>Getting Error:</p>
  
  <pre><code>---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-77-4ff34d9ac4c9&gt; in &lt;module&gt;
  ----&gt; 1 bc.save()
  
  ~/Desktop/workspace/projects/barcodescan/scan/models.py in save(self, *args, **kwargs)
       19         code = get_random_string(length=11, allowed_chars='1234567890')
       20         self.code = str(code)
  ---&gt; 21         super(BarCode, self).save(*args, **kwargs)
       22 
       23     def __str__(self):
  
  ~/Desktop/workspace/projects/barcodescan/venv/lib/python3.5/site-packages/django/db/models/base.py in save(self, force_insert, force_update, using, update_fields)
      739 
      740         self.save_base(using=using, force_insert=force_insert,
  --&gt; 741                        force_update=force_update, update_fields=update_fields)
      742     save.alters_data = True
      743 
  
  ~/Desktop/workspace/projects/barcodescan/venv/lib/python3.5/site-packages/django/db/models/base.py in save_base(self, raw, force_insert, force_update, using, update_fields)
      777             updated = self._save_table(
      778                 raw, cls, force_insert or parent_inserted,
  --&gt; 779                 force_update, using, update_fields,
      780             )
      781         # Store the database on which the object was saved
  
  ~/Desktop/workspace/projects/barcodescan/venv/lib/python3.5/site-packages/django/db/models/base.py in _save_table(self, raw, cls, force_insert, force_update, using, update_fields)
      846             base_qs = cls._base_manager.using(using)
      847             values = [(f, None, (getattr(self, f.attname) if raw else f.pre_save(self, False)))
  --&gt; 848                       for f in non_pks]
      849             forced_update = update_fields or force_update
      850             updated = self._do_update(base_qs, using, pk_val, values, update_fields,
  
  ~/Desktop/workspace/projects/barcodescan/venv/lib/python3.5/site-packages/django/db/models/base.py in &lt;listcomp&gt;(.0)
      846             base_qs = cls._base_manager.using(using)
      847             values = [(f, None, (getattr(self, f.attname) if raw else f.pre_save(self, False)))
  --&gt; 848                       for f in non_pks]
      849             forced_update = update_fields or force_update
      850             updated = self._do_update(base_qs, using, pk_val, values, update_fields,
  
  ~/Desktop/workspace/projects/barcodescan/venv/lib/python3.5/site-packages/django/db/models/fields/files.py in pre_save(self, model_instance, add)
      284     def pre_save(self, model_instance, add):
      285         file = super().pre_save(model_instance, add)
  --&gt; 286         if file and not file._committed:
      287             # Commit the file to storage prior to saving the model
      288             file.save(file.name, file.file, save=False)
  
  AttributeError: 'Image' object has no attribute '_committed'
  </code></pre>
  
  <p>I am not able to find the solution for this, I request you to please suggest me some solution to solve this. it will be very grateful for me. Thanks in advace</p>