I
I
ixotep2020-03-20 13:37:08
Video cards
ixotep, 2020-03-20 13:37:08

How to upload an image using Django rest framework?

Hello!
Unable to update values ​​in post, error occurs:

img_post: ["Uploaded file is not a valid file."]


serializer.py
class PostsSerializer(TaggitSerializer, serializers.ModelSerializer):
    tags = TagListSerializerField()
    views_sum = serializers.IntegerField(source='views_post.views_sum')
    rating = serializers.IntegerField(source='views_post.rating')

    def save(self, **kwargs):
        obj, views = ViewsPost.objects.get_or_create(post_views=self.instance.id)
        vd_views = self.validated_data.get('views_post')
        obj.views_sum = vd_views['views_sum']
        obj.rating = vd_views['rating']
        obj.save()

    class Meta:
        model = Posts
        fields = ('id', 'title', 'category', 'img_post', 'date',
                  'preview', 'post_text', 'approved', 'slug', 'tags', 'views_sum', 'rating')


views.py
class PostsViewSet(viewsets.ModelViewSet):
    serializer_class = PostsSerializer
    queryset = Posts.objects.filter(approved=True)
    lookup_field = 'slug'
    filter_backends = [DjangoFilterBackend]
    filterset_fields = ['category__slug']


js

async submitRating(rat) {
        let formData = new FormData();
        for (let data in this.post) {
          formData.append(data, this.post[data]);
        }
        let dataPost = this.post;
        dataPost.rating = +dataPost.rating + rat;
        try {
          let response = await this.$axios.$put('/posts/' + this.post.slug + '/', dataPost);
        } catch (e) {
          console.log(e.toString())
        }
      }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
r1mple, 2019-08-25
@r1mple

Thanks everyone for the replies.
I decided to check the indicators in Hades, it turned out that the percentage is heated by 80% and because of this, the percentage went into throttling.
I didn’t take out the cooler, because I took the percentage for the old processor, namely 4330, although I don’t know why, because before everything was ok. In general, I changed the cooler and everything was fine.

R
Radjah, 2019-08-21
@Radjah

Well, rejoice that the card draws graphics better than the processor logic.
You can run a hairy donut, then the processor will idle, and the vidyuha will plow and warm up.

N
noremorse_ru, 2020-03-20
@noremorse_ru

headers: {
      'Content-Type': 'multipart/form-data'
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question