Questions tagged [imagefield]

A place to store or display a graphic image.

"Image field" is a generic term that typically would belong in a or setting such as:

It appears to be a synonym for .

342 questions
94
votes
13 answers

How do I get Django Admin to delete files when I remove an object from the database/model?

I am using 1.2.5 with a standard ImageField and using the built-in storage backend. Files upload fine but when I remove an entry from admin the actual file on the server does not delete.
narkeeso
  • 2,037
  • 1
  • 17
  • 14
48
votes
1 answer

How to check ImageField is empty

I have an ImageField in my model and when I'm saving it I want to check that if it's None or not. In django shell I'm calling my object's ImageField and it gives : >>> p.avatar >>> p.avatar is None False I found that the…
iva123
  • 3,395
  • 10
  • 47
  • 68
31
votes
4 answers

Django: Get ImageField url in view

I am trying to get ImageField absolute path in Django view so I can open the image, write on it something and then serve it to user. I have problem getting absolute path for the image which is saved in media folder. item = get_object_or_404(Item,…
Byteme
  • 589
  • 2
  • 6
  • 10
29
votes
4 answers

Override django's model delete method for bulk deletion

I'm overriding Django's model delete method in order to delete orphan files in the disk for image fields, something like this: class Image(models.Model): img = models.ImageField(upload_to=get_image_path) ... def delete(self, *args,…
Kilian Perdomo Curbelo
  • 1,281
  • 1
  • 15
  • 31
28
votes
15 answers

django.db.utils.IntegrityError: NOT NULL constraint failed: products_product.image ERROR WITH IMAGE FIELD

I wanna add ImageField to my Product model and upload it to my media_cdn directory but when I migrate my base to my model.py it returns the below error: django.db.utils.IntegrityError: NOT NULL constraint failed: products_product.image ERROR WITH…
Kronvid Vladimir
  • 608
  • 1
  • 7
  • 14
26
votes
8 answers

Replacing a Django image doesn't delete original

In Django, if you have a ImageFile in a model, deleting will remove the associated file from disk as well as removing the record from the database. Shouldn't replacing an image also remove the unneeded file from disk? Instead, I see that it keeps…
Shige Abe
  • 267
  • 1
  • 3
  • 4
25
votes
3 answers

Django - Display ImageField

I've just started to use Django and I haven't found a lot of info on how to display an imageField, so I made this: models.py: class Car(models.Model): name = models.CharField(max_length=255) price = models.DecimalField(max_digits=5,…
unixeo
  • 1,116
  • 1
  • 15
  • 28
24
votes
3 answers

Django: manually create imagefield in model from existing file on server

This is killing me! I'm using django-filebrowser, and I want to create a gallery app that leverages it's upload capabilities to manage images. I have a Gallery model that allows the user to select or create a directory on the server, and upload…
Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
20
votes
2 answers

how to go from django image field to PIL image and back?

Given a django image field, how do I create a PIL image and vice-versa? Simple question, but hard to google :( (I'm going to use django-imagekit 's processor to rotate an image already stored as model attribute.) edit In [41]:…
eugene
  • 39,839
  • 68
  • 255
  • 489
15
votes
2 answers

Image file not deleted when object with ImageField field is deleted

I've got a model Picture with an ImageField. When deleting an instance of Picture, the file set in the ImageField is not deleted. Is it a bug? How can I do it?
jul
  • 36,404
  • 64
  • 191
  • 318
13
votes
3 answers

django S3 - trim imagefield filename but not the url path

this is a followup to my question here: ImageField / FileField Django form Currently unable to trim the path to filename In my Django app, there is an imagefield uploaded to S3 After trim the imagefile path name, the image is not accessible because…
Axil
  • 3,606
  • 10
  • 62
  • 136
12
votes
3 answers

Django UpdateView / ImageField issue: not returning new uploaded image

model: class Logo(models.Model): media = models.ImageField(upload_to='uploads') def __unicode__(self): return self.media.url view: class LogoEdit(UpdateView): model = Logo template_name = 'polls/logo-edit.html' success_url =…
11
votes
2 answers

Django - How can I display a photo saved in ImageField?

I've been going around in circles for hours with this. I have a UserProfile model with profile_pic ImageField. I saved the user photo and now I want to display it, but nothing works. I went through docs, SO, google, with no result. I uploaded a…
user1102018
  • 4,369
  • 6
  • 26
  • 33
11
votes
2 answers

How to rename currently, Clear and Change labels in ImageField of Django

I am relatively new to django. I am using ImageForm to get the image path from the user. class EditProfileForm(ModelForm): username = CharField(label='User Name', widget=TextInput(attrs={'class': 'form-control'}), required=True) image =…
Niraj Chapla
  • 2,149
  • 1
  • 21
  • 34
11
votes
1 answer

Django ImageField default

models.py: class UserProfile(models.Model): photo = models.ImageField(upload_to = get_upload_file_name, storage = OverwriteStorage(), default =…
Mihai Zamfir
  • 2,167
  • 4
  • 22
  • 37
1
2 3
22 23