django-rest-framework

django rest framework doesn't accept blob picture file (File extension “” is not allowed)

允我心安 提交于 2021-01-28 02:15:46
问题 I am trying to update a User Profile by making a multipart/form-data put request (from my vue frontend using axios) containing a png blob image file. I receive an error message: File extension “” is not allowed. This is the File Field on the Userprofile Model: profile_picture = models.FileField( _("Profile Pictures"), upload_to="profile_picture", max_length=100, blank=True, null=True, ) These are the signals I use in the Userprofile model to save and update the Model. @receiver(post_save,

How to add change password functionality to Django / React app

可紊 提交于 2021-01-28 02:06:47
问题 I'm trying to add change password functionality to a Django / React app. I'm struggling to find any way to make this work. I'm using django-rest-auth and django-rest-framework. I would be happy to either submit the password change request from a React page, or else to redirect the user to the native Django template-driven page - leaving my SPA, but acceptable to get the functionality working. However, the change password page requires the user to be logged in, and I can't see how to do this

Django REST Framework and combining models

こ雲淡風輕ζ 提交于 2021-01-28 00:53:26
问题 Updated question I was able to get it to work and have updated the codes below. But now my question is how can the fields in iceinfo be edited? As it stands now it is returned as IceInfo object and not as editable fields. I can edit ice_code and ice_maker only. Old question I'm trying to build an API for our database. The information in the database is divided between multiple tables, all of which have the same ' Ice-code ' as their primary key. I've been trying now for a better part of a

Serve images with django-rest-framework

久未见 提交于 2021-01-27 20:00:17
问题 I am trying to serve images from an api based on django-rest-api. So far I have a very basic api view that loads an image and its mimetype and returns it. @api_view(['GET']) def get_pic(request, pk=None, format=None): //get image and mimetype here return HttpResponse(image, content_type=mimetype) This has been working fine, however I have tested it on some new image libraries on iOS and have found that the API is returning a 406 error. I believe this is because the client is sending a Accept

Django annotate field value from another model

会有一股神秘感。 提交于 2021-01-27 19:23:23
问题 I want to annotate MyModel queryset with a value from another History model. My models relations are the following: class Stage(models.Model): name = models.CharField() class History(models.Model): mymodel = models.ForeignKey( MyModel, on_delete=models.CASCADE, ) stage = models.ForeignKey( Stage, on_delete=models.DO_NOTHING ) created_at = models.DateTimeField( auto_now_add=True ) class MyModel(models.Model): id = models.AutoField( primary_key=True, ) ... Approximate operation I'd like to

How do I mock a third party library inside a Django Rest Framework endpoint while testing?

我怕爱的太早我们不能终老 提交于 2021-01-27 14:31:15
问题 The user creation endpoint in my app creates a firebase user (I have a chat room inside the app, powered by firebase) with the same id as my django user. from django.contrib.auth.models import User from rest_framework import generics from rest_framework import permissions from apps.core.services import firebase_chat class UserCreate(generics.GenericAPIView): permission_classes = [permissions.AllowAny] @transaction.atomic def put(self, request): user = User.objects.create(**request.data)

Django REST Framework — is multiple nested serialization possible?

蹲街弑〆低调 提交于 2021-01-27 13:01:39
问题 I would like to do something like the following: models.py class Container(models.Model): size = models.CharField(max_length=20) shape = models.CharField(max_length=20) class Item(models.Model): container = models.ForeignKey(Container) name = models.CharField(max_length=20) color = models.CharField(max_length=20) class ItemSetting(models.Model): item = models.ForeignKey(Item) attribute_one = models.CharField(max_length=20) attribute_two = models.CharField(max_length=20) serializers.py class

Django rest framework custom return response

五迷三道 提交于 2021-01-27 12:12:05
问题 So I have this custom register API which registers a user, but when user successfully register, I want it to have this message "You have successfully register an account!" But I tried a different method but get an error instead. serializer.py class UserCreate2Serializer(ModelSerializer): email = EmailField(label='Email Address') valid_time_formats = ['%H:%M', '%I:%M%p', '%I:%M %p'] birthTime = serializers.TimeField(format='%I:%M %p', input_formats=valid_time_formats, allow_null=True, required

Django-Rest-Framework. Hyperlink entities via query parameters

霸气de小男生 提交于 2021-01-27 07:15:47
问题 I have two models: Field and Set. And I want to have hyperlink to Fields which compose concrete set. for example: url: sets/ should return [{'title': 'dimensional', 'fieldsLink': '#url-to-enpoin'}] There is nothing complicated to write something like this: class Field(models.Model): title = models.CharField(max_length=255, blank=True, null=True) set = models.ForeignKey(Set, related_name='fields', blank=True, null=True) class Set(models.Model): title = models.CharField(max_length=255, blank

Differences between RESTful API and urlpatterns router in Django

情到浓时终转凉″ 提交于 2021-01-27 06:58:24
问题 Am new to web developpement and wondering the differences between: Django Restful API and standard Django URL routers urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', views.index, name='Index'), url(r'^getvalue/$', views.get_points, name='Get Points'), url(r'^putvalue/$', views.put_points, name='Put Points'), ] What are the benefits of setting Django restful API when interacting with Javascript components since both are JSON sending URL ? 回答1: Before understanding this you have