django-uploads

Image uploaded but not saved in media and database Django

别来无恙 提交于 2020-12-26 12:05:55
问题 Am creating a settings page where the user should be able to chang there image and biodata. But only the biodata gets updated when I print the request.FILES.GET("profile_picture") it prints the name of the photo I uploaded. why is it not uploaded and saved to the database? Models.py from django.db import models from django.contrib.auth.models import AbstractUser class User(AbstractUser): profile_pic = models.ImageField(upload_to="images/", null=True ,blank=True) bio = models.TextField(max

Image uploaded but not saved in media and database Django

不羁岁月 提交于 2020-12-26 12:04:59
问题 Am creating a settings page where the user should be able to chang there image and biodata. But only the biodata gets updated when I print the request.FILES.GET("profile_picture") it prints the name of the photo I uploaded. why is it not uploaded and saved to the database? Models.py from django.db import models from django.contrib.auth.models import AbstractUser class User(AbstractUser): profile_pic = models.ImageField(upload_to="images/", null=True ,blank=True) bio = models.TextField(max

Serialize multiple InMemoryUploadedFile using ListField : Django REST Framework

故事扮演 提交于 2020-06-29 03:56:21
问题 How can I serialize multiple InMemoryUploadedFile using serializers.ListField() ?? code snippet #views.py @api_view(['POST', 'GET']) def create_post(request): if request.method == 'POST': altered_request_data = request.data.copy() in_memory_upload_files_list = [value for value in request.FILES.values()] altered_request_data['files'] = in_memory_upload_files_list serializer = PostSerializer(data=altered_request_data) serializer.is_valid(raise_exception=True) serializer.save() return Response

Serialize multiple InMemoryUploadedFile using ListField : Django REST Framework

不打扰是莪最后的温柔 提交于 2020-06-29 03:55:08
问题 How can I serialize multiple InMemoryUploadedFile using serializers.ListField() ?? code snippet #views.py @api_view(['POST', 'GET']) def create_post(request): if request.method == 'POST': altered_request_data = request.data.copy() in_memory_upload_files_list = [value for value in request.FILES.values()] altered_request_data['files'] = in_memory_upload_files_list serializer = PostSerializer(data=altered_request_data) serializer.is_valid(raise_exception=True) serializer.save() return Response

Display image from ImageField by means of form

十年热恋 提交于 2020-01-23 09:58:17
问题 prelude : Here's the simpliest way to display an ImageField. Lets assume I have 10 fields in my form and I don't wanna iterate over all of them in template.html just to check if it's an imageField and display it in a different way. I want to handle it via form or widget or something like this. So I want the leave template.html as it's bellow. template.html <table> {{ form.as_table }} </table> And add to models.py an image_tag method: class UserProfile(Model): photo = ImageField(upload_to

Django: Validate file type of uploaded file

笑着哭i 提交于 2019-12-28 04:50:08
问题 I have an app that lets people upload files, represented as UploadedFiles . However, I want to make sure that users only upload xml files. I know I can do this using magic , but I don't know where to put this check - I can't put it in the clean function since the file is not yet uploaded when clean runs, as far as I can tell. Here's the UploadedFile model: class UploadedFile(models.Model): """This represents a file that has been uploaded to the server.""" STATE_UPLOADED = 0 STATE_ANNOTATED =

Multiple images in django form with multiupload

为君一笑 提交于 2019-12-24 01:17:45
问题 I need to add multiple images in django form to one model. I did a research and for form outside of django I try to setup django-multiupload. My models.py: class Profile(models.Model): ... ... first = models.ImageField("first", upload_to='first') second = models.ImageField("second", upload_to='second') ... In forms.py: class AddForm(forms.ModelForm): first = MultiImageField(min_num=1, max_num=20) second = MultiImageField(min_num=1, max_num=4) In views.py: class UploadView(FormView): template

Django / file uploads permissions

怎甘沉沦 提交于 2019-12-20 16:18:12
问题 I wrote a django app, but I have a little problem with the file permissions of the uploads files from a web form. Basically I can upload a .mp3 file but it always keep chmod 600. The container folder has chmod 775, and the umask is set to 022. I'm in a shared hosting service. 回答1: Try this in your settings.py if you use Python 2: FILE_UPLOAD_PERMISSIONS = 0644 In Python 3 octal numbers must start with 0o so the line would be: FILE_UPLOAD_PERMISSIONS = 0o644 For more details see the

Django-models: use field from foreign key

时光总嘲笑我的痴心妄想 提交于 2019-12-13 16:19:08
问题 I'm working on an image gallery project in DJango, just for the sake of it. And well, I have a class named Gallery and a class named ImageGallery . The class named gallery would look like this: class Gallery(models.Model): gallery = models.ForeignKey(Gallery, related_name="parent_gallery") title = models.CharField(max_length=200) folder = models.CharField(max_length=200) # ex: images/galleries/slugify(self.title) class ImageGallery(models.Model): gallery = models.ForeignKey(Gallery, related

Simple Django Image Upload - Image file not saving

可紊 提交于 2019-12-12 07:38:44
问题 Right I'm learning how to do a simple image upload form to upload an image to MEDIA_ROOT. The form renders fine, I get no errors, but the file is not showing up in the MEDIA_ROOT directory. If followed the documentation example and can't get it to work and I know it is because I have not understood django file upload handeling properly. So here is my code: forms.py from django import forms class UploadImageForm(forms.Form): image = forms.ImageField() views.py def merchant_image_upload(request