django-rest-framework

Lists are currently not supported in HTML Input

若如初见. 提交于 2021-01-29 20:19:42
问题 I am having this problem with my browsable API: "Lists are not currently supported in HTML input." Here are my models: class Breed(models.Model): name = models.CharField(max_length=150) def __str__(self): return self.name class BreedImage(models.Model): breed = models.ForeignKey(Breed, related_name='BreedImages', on_delete=models.CASCADE) breedImage = models.ImageField(upload_to='photos', null=True, blank=True) My Serializers: class ImageSerializer(serializers.ModelSerializer): class Meta:

Django Edit Or Delete Selected Rows In A Table - ListView

折月煮酒 提交于 2021-01-29 18:56:26
问题 I have a table with checkboxes and I would like to be able to delete or edit a specific field value for all the selected rows in the table. Here's an example table that would be awesome to recreate but I have not found examples anywhere how this may work in the view and template. https://examples.bootstrap-table.com/# My current view, which is working with a table. Where can I start to make the leap from a basic table to an interactive one like in the example above? Views.py class EntryList

Django easy-thumbnails serialize with Django Rest Framework

醉酒当歌 提交于 2021-01-29 17:55:03
问题 The docs on their GitHub page suggests that what I'm trying to do should work: thumb_url = profile.photo['avatar'].url In my project, it gives an error: THUMBNAIL_ALIASES = { '': { 'thumb': {'size': (64, 64), 'upscale': False}, }, } class Image(models.Model): place = models.ForeignKey(Place, models.CASCADE, 'images') image = ThumbnailerImageField(upload_to='') class ImageSerializer(serializers.Serializer): image = serializers.ImageField() thumb = serializers.ImageField(source='image.image[

Correct way to pass huge JSON API response (Django REST)

荒凉一梦 提交于 2021-01-29 17:04:06
问题 I have a task to pass huge JSON response and would like to understand what is the best practice for that. What I'm doing right now is using StreamHttpResponse : def generator_chunk(): ... yield df.to_json # returns data like [json] @api_view(['GET']) def return_data(request): ... return StreamHttpResponse(generator_chunk) # streams data like [json][json], which is not proper json format Few options I have right now on how to solve it: Create temp file and store all chunks there - then stream

Django throws ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

ⅰ亾dé卋堺 提交于 2021-01-29 16:39:26
问题 Sorry in advance if my question looks obscure. This is the error thrown by Django when I'm trying to serve multiple Django media(videos) URLs in my React homepage.This is the stacktrace: Exception happened during processing of request from ('127.0.0.1', 5511) File "D:\Django\myproject\app\env\lib\site-packages\django\core\servers\basehttp.py", line 174, in handle self.handle_one_request() Traceback (most recent call last): File "C:\Users\Anshul\AppData\Local\Programs\Python\Python38\lib

create() argument after ** must be a mapping, not list, Django REST Framework (implementing my own create method error)

对着背影说爱祢 提交于 2021-01-29 16:38:08
问题 when I am implementing this code-example on the documentation (I had to implement the create method myself because I have nested objects and inserting them is not supported by default) def create(self, validated_data): profile_data = validated_data.pop('profile') user = User.objects.create(**validated_data) Profile.objects.create(user=user, **profile_data) return user https://www.django-rest-framework.org/api-guide/serializers/#writing-create-methods-for-nested-representations I'm getting

python ForeignKey relation with user shows this error NOT NULL constraint failed: music_song.performer_id

北战南征 提交于 2021-01-29 15:45:15
问题 Fellow programmers, I am getting a error NOT NULL constraint failed: music_song.performer_id I want the performer field to be the user who is creating the song but its not happening I have tried a lot can you guys please help me out with it models.py class Song(models.Model): name = models.CharField(_("Name"), max_length=50) song = models.FileField(_("Song"), upload_to=None, max_length=100) song_image = models.ImageField(upload_to=None, height_field=None, width_field=None,max_length=100)

Parameters URL with DRF routers

痞子三分冷 提交于 2021-01-29 14:26:13
问题 I'm using Django Rest Framework for created a API. In this project i want to capture parameters in the URL. For example i want to capture the username and password of a user and my idea is like this: http://localhost:8000/accounts/login/?unsername=username&password=password But i cant, I' usin routers and django-filter, but i cant get the parameters url. My project files are there: view.py: class AccountsData(viewsets.ModelViewSet): queryset = models.UserData.objects.all() serializer_class =

Unable to POST data with foreign key relationship - Django rest

痞子三分冷 提交于 2021-01-29 14:08:44
问题 Here are my models : User - I am using the default User provided by django admin class UserProfile(models.Model): user = models.ForeignKey(User,on_delete=CASCADE,related_name='user') phonenumber=models.IntegerField() picture=models.CharField(max_length=20,null=True) #dp=models.ImageField(upload_to='profile_pics',blank=True) points=models.IntegerField(default=0) def __str__(self): return self.user.name def __repr__(self): return str(self.user.name) Here is my View where I am trying to post the

Django : How to write Django Group by and where Condition?

放肆的年华 提交于 2021-01-29 13:24:40
问题 I have Django Model with five fields and I mention two fields in serializer class.I need to perform group by and where ClosingStock>0 condition. I have tried with this query but am not getting output. StoreClosingStock.objects.filter(CLOSING_STOCK__gte="0").values('ITEM_CODE','CLOSING_STOCK') I have implemented the same query in mysql its working fine .I want the same output in Django Views.py class StoreClosingViewset(viewsets.ModelViewSet): serializer_class = StoreClosingStockSerializer