imagefield

How to prevent Django from changing file name when a file with that name already exists?

雨燕双飞 提交于 2019-12-09 06:38:00
问题 In my case I allow user to upload an avatar picture and use user_id as filename, simply. So there will be 1.jpg, 2.jpg, etc. However I found if I upload a new avatar for some account that already has one uploaded, let's say user #10, the new file will be named as "10_1.jpg". This is OKay, however I don't need it and I hope new file could overwrite the old one - it also saves some disk space anyway. I googled and searched but couldn't find a clue. I was hoping there would be an option for

django S3 - trim imagefield filename but not the url path

空扰寡人 提交于 2019-12-08 15:41:34
问题 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 the url is trimmed. How can I trim the display but don't trim the path? I manage to trim the display showing the filename like this class CustomClearableFileInput(ClearableFileInput): def get_context(self, name, value, attrs): logging.debug("%s"

Django custom validation in model form for imagefield (max file size etc.)

强颜欢笑 提交于 2019-12-06 07:24:02
问题 I have a modelform that has an imagefield called 'banner' and I am trying to validate the file size and dimesions and provide an error if the image is too large. Here is the models.py: class Server(models.Model): id = models.AutoField("ID", primary_key=True, editable=False) servername = models.CharField("Server Name", max_length=20) ip = models.CharField("IP Address", max_length=50) port = models.CharField("Port", max_length=5, default='25565') banner = models.ImageField("Banner", upload_to=

Drupal 7: Rename files on upload (via filefield)

浪尽此生 提交于 2019-12-06 00:44:19
I am looking for a way to rename files that are uploaded by users through a filefield. For example, rename user profile photos using uniqid . I found a good solution for D6 at " Drupal 6: How to Change Filename on Upload " but can't find anything for D7. Another option is to use File (Field) Paths , but: The module causes warnings on my setup. Seems to be a bit of an overkill to install a general module for a very specific purpose. You can change every file upload by hook_file_presave as your desire pattern as example function yourmodulename_file_presave($file) { $parts = pathinfo($file-

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

岁酱吖の 提交于 2019-12-04 17:30:27
问题 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]: m.image_1.__class__ Out[41]: django.db.models.fields.files.ImageFieldFile In [42]: f = StringIO(m.image_1.read()) In [43]: Image.open(f) --------------------------------------------------------------------------- IOError Traceback (most recent call last) <ipython-input

Django custom validation in model form for imagefield (max file size etc.)

不想你离开。 提交于 2019-12-04 11:52:00
I have a modelform that has an imagefield called 'banner' and I am trying to validate the file size and dimesions and provide an error if the image is too large. Here is the models.py: class Server(models.Model): id = models.AutoField("ID", primary_key=True, editable=False) servername = models.CharField("Server Name", max_length=20) ip = models.CharField("IP Address", max_length=50) port = models.CharField("Port", max_length=5, default='25565') banner = models.ImageField("Banner", upload_to='banners', max_length=100) description = models.TextField("Description", blank=True, max_length=3000)

How to improve performance in SQL Server table with image fields?

不想你离开。 提交于 2019-12-04 06:21:17
I'm having a very particular performance problem at work! In the system we're using there's a table that holds information about the current workflow process. One of the fields holds a spreadsheet that contains metadata about the process (don't ask me why!! and NO I CAN'T CHANGE IT!!) The problem is that this spreadsheet is stored in an IMAGE field in an SQL Server 2005 (within a database set with SQL 2000 compatibility). This table currently has 22K+ lines and even a simple query like this: SELECT TOP 100 * FROM OFFENDING_TABLE Takes 30 seconds to retrieve the data in Query Analyser. I'm

Add Class to Image Field in Drupal 7

蹲街弑〆低调 提交于 2019-12-03 21:02:11
I have added an image field to content type "Basic Page" and using the "Manage Displays" option have it displayed at the top of the page. However there is no styling on the image and I can't for the life of me figure out how I add a class to the image so that I can add styles. If you're using CCK there's almost certainly a class already associated with the image (or at least a class on a div that wraps it). CCK wraps just about everything in a class. Try right clicking the image and clicking on Inspect Element to double check. If you really need to add a class though, you can use the Theme

How to check ImageField is empty

守給你的承諾、 提交于 2019-12-03 14:33:33
问题 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 <ImageFieldFile: None> >>> p.avatar is None False I found that the ImageField's name is u'', so is there any better way to do it ? 回答1: I found that the ImageField's name is u'', so is there any better way to do it ? Actually, it looks like that's exactly how this class evaluates bool() , so the better way is to just

How to check ImageField is empty

故事扮演 提交于 2019-12-03 05:20:53
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 <ImageFieldFile: None> >>> p.avatar is None False I found that the ImageField's name is u'', so is there any better way to do it ? I found that the ImageField's name is u'', so is there any better way to do it ? Actually, it looks like that's exactly how this class evaluates bool() , so the better way is to just test its bool() by calling if p.avatar ImageFieldFile subclasses File , which defines: def __nonzero__(self):