FAQ Database Discussion Community


Override django's model delete method for bulk deletion

django,model,delete,bulk,imagefield
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, **kwargs): self.img.delete() super(Image, self).delete(*args, **kwargs) This works fine when i delete single objects from the admin, but when i select...

Django: Querying to ImageField all images are being rendered

python,django,imagefield
So my problem is that when I try to query to the image url so it can be posted to its corresponding Post all the images that have been uploaded to the media folder is being rendered, even though in the admin panel it shows that each post has it's...

Using .update with nested Serializer to post Image

django,rest,django-models,django-rest-framework,imagefield
I have an ImageField. When I update it with the .update command, it does not properly save. It validates, returns a successful save, and says it is good. However, the image is never saved (I don't see it in my /media like I do my other pictures), and when it...

Django, two ImageField pointing to the same file

django,imagefield,django-imagekit
I'd like my two image fields point to the same image. At one time, I'll have one image field populated. At later time, I'd like another imageField to point to the same file. (If the first one changes, the second one gets updated as well) The file is at amazon...

How to display uploaded django ImageField in django/mezzanine template?

django,apache,django-templates,mezzanine,imagefield
I don't have a clue here. I've set up a form with ImageField to upload user images via frontend and upload is working fine, though I can't find a way to retrieve the pics url and display it in a template. I did run python manage.py collectstatics. Template files and...

How to change upload_to parameter of ImageField based on field name in Django?

django,models,filefield,imagefield
I would like to upload images to the media root based on the field values given by the Django admin user. Here is the code that I've written and I know that the upload_to parameter is causing the problem. But I don't know how to make it work. models.py class...

Can't create image field in Django app

python,django,python-3.x,imagefield,factory-boy
I'm working on a Django app whose core functionality is based around storing photo albums. I'm using Django 1.8.1 with Python 3. Here are the models I've created so far: import uuid from django.db import models from django.conf import settings from django.utils import timezone # Create your models here. class...