An issue with removing files from custom model

23 views
Skip to first unread message

Jakub Lamprecht

unread,
Apr 15, 2016, 8:42:44 AM4/15/16
to django-filer
Hey,

at first I wanted to mention that I'm no expert in Python/Django. So I have this app that is a storage an each stored item has an image. The problem is that when I click the red cross next to the picture or check box in item modification page in administration panel and then click save i get this error: "

'NoneType' object has no attribute 'original_filename'



On the other hand, deleting this image file directly from filer page works flawlessly, no problems whatsoever, but it deletes the file from file manager which i want to aviod.

My item model code:


class Item(models.Model):
    symbol
= models.CharField(max_length=60)
    slug
= models.SlugField(max_length=255, unique=True, help_text="Skrócona nazwa wyświetlana w adresie URL.")
    quantity
= models.PositiveIntegerField(default=1, verbose_name="ilość")
    manufacturer
= models.ForeignKey(Manufacturer, blank=True, null=True, verbose_name="producent")
    location
= models.ForeignKey(Location, blank=True, null=True, verbose_name="lokalizacja")
    short_description
= models.CharField(blank=True, max_length=60, verbose_name="skrócony opis", help_text="Opis wyświetlany na liście elementów.")
   
# TODO: Zwieksz max_length powyzej, ale sprawdz czy przy max. dlugosci sie nie rozjezdzaja komorki...
    description
= models.TextField(blank=True, verbose_name="opis")
    for_rent
= models.BooleanField(default=False, verbose_name="tylko do wypożyczenia")
    category
= TreeForeignKey(Category, blank=True, null=True, verbose_name="kategoria")
   
# In case if one item could be in many categories
   
# categories = TreeManyToManyField(Category, blank=True, null=True)
   
# parameter = models.ForeignKey(ParameterOfItem)
    barcode
= models.CharField(blank=True, max_length=16, null=True, verbose_name="kod kreskowy")
   
# TODO: Render barcode on .\templates\inventory\detail.html
    created
= models.DateTimeField(auto_now_add=True, verbose_name="data utworzenia")
    modified
= models.DateTimeField(auto_now=True, verbose_name="data modyfikacji")
 
   
def __unicode__(self):
       
return self.symbol
       
# return u'%s %s' % (self.manufacturer, self.symbol)
 
   
class Meta:
        ordering
= ['symbol']
        verbose_name
= "element"
        verbose_name_plural
= "elementy"

and ItemImage class:

class ItemImage(models.Model):
    image
= FilerImageField(blank=True, null=True, verbose_name="obrazek")
    item
= models.ForeignKey(Item)
 
   
def __unicode__(self):
       
return self.image.original_filename
 
   
class Meta:
        verbose_name
= "obrazek"
        verbose_name_plural
= "obrazki"

Deleting image directly from the filer deletes the itemimage database record, but the red cross in item modification page does not. I have no idea what to do about it, any ideas?


Reply all
Reply to author
Forward
0 new messages