Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django - Bizarre behavior of reverse() in tests
I've been stuck on the following bug for about an hour and I can't figure out what is happening. Consider the following: class BoardViewTests(TestCase): def setUp(self): self.user = User.objects.create_user( username='testuser', email='test@test.com', password='very_secret', ) self.user.refresh_from_db() self.test_board = Board.objects.create(name='test board', description='board test description') self.test_topic = Topic.objects.create(name='test topic', board=self.test_board, starter=self.user.profile) def test_board_view_shows(self): response = self.client.get(reverse('boards:board', args=('testboard',))) # Slug value here is 'test-board' # (Tested with print statement) self.assertEquals(response.status_code, 200) self.assertContains(response, 'test board') self.assertContains(response, 'board test description') ... and the following url conf: app_name = 'boards' urlpatterns = [ path('', views.index, name='index'), path('boards', lambda request: redirect(reverse('boards:index'), permanent=True)), path('boards/<slug:board_slug>', views.board, name='board'), path('boards/<slug:board_slug>/<int:topic_id>', views.topic, name='topic'), ] When I run the test, it gives me the following exception: django.urls.exceptions.NoReverseMatch: Reverse for 'topic' with arguments '('test board', 1)' not found. 1 pattern(s) tried: ['boards/(?P<board_slug>[-a-zA-Z0-9_]+)/(?P<topic_id>[0-9]+)$'] What happens to the hyphen, and why is there a 1 in the arguments it shows? Since there are now supposedly 2 arguments, it tries matching against the next path ('topic'). I've tried replacing the argument by 'test-board' and I get the same output. When I use any string without hyphens, the problem doesn't occur: the url is correctly matched and the assert fails because it is a 404. Also worth noting that everything … -
why codecanyon just have 1 django project?
I search a lot of places to buy djnago project same like php which is sold in codecanyon but i am surprised there is only 1 project in codecanynon . I also tried to look a site who sells djnago proejct but i do not see any website . I want to know why is that or there is legal issue behind it. -
Create-react-app: unhandled error event: Events.js.187
'm trying to create a new react app with yarn. after using the command create-react-app i keep getting an error unhandled events error. There's also a reference to django-admin.py in the error log for some reason and I can't make out the connection.Can i get some assistance. the log of the error is shown below Installing packages. This might take a couple of minutes. Installing react, react-dom, and react-scripts... events.js:187 throw er; // Unhandled 'error' event ^ Error: spawn C:\Windows\system32\cmd.exe;C:\Users\HP\AppData\Local\Programs\Python\Python36\Scripts\django-admin.py ENOENT [90m at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)[39m [90m at onErrorNT (internal/child_process.js:456:16)[39m [90m at processTicksAndRejections (internal/process/task_queues.js:80:21)[39m Emitted 'error' event on ChildProcess instance at: at ChildProcess.cp.emit (C:\Users\HP\AppData\Local\Yarn\Data\global\node_modules\[4mcross-spawn[24m\lib\enoent.js:34:29) [90m at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)[39m [90m at onErrorNT (internal/child_process.js:456:16)[39m [90m at processTicksAndRejections (internal/process/task_queues.js:80:21)[39m { errno: [32m'ENOENT'[39m, code: [32m'ENOENT'[39m, syscall: [32m'spawn C:\\Windows\\system32\\cmd.exe;C:\\Users\\HP\\AppData\\Local\\Programs\\Python\\Python36\\Scripts\\django-admin.py'[39m, path: [32m'C:\\Windows\\system32\\cmd.exe;C:\\Users\\HP\\AppData\\Local\\Programs\\Python\\Python36\\Scripts\\django-admin.py'[39m, spawnargs: [ [32m'/d'[39m, [32m'/s'[39m, [32m'/c'[39m, [32m'"npm ^"install^" ^"--save^" ^"--save-exact^" ^"--loglevel^" ^"error^" ^"react^" ^"react-dom^" ^"react-scripts@0.9.x^""'[39m ] } C:\Users\HP\Documents\web dev\Angular 2>cd C:\Users\HP\Documents\web dev\Angular 2create-react-app my-app -
Django best why to Implement Memcached in blog site
I am using python/Django in my project with Memcache. I just want to know what is best why to Memcache Implement Memcache in the Django blog site. -
Django Default Css missing
I've reading the old posts about the CSS missing in Django projects but I didn't find the answer to my problem. I didn't make any change in any static file from the beginning of the building of the API and suddenly the HTML stopped to get the CSS properties. What can happen for this behavior? I also tried with python manage.py collectstatic after setting the STATIC_URL, STATIC_ROOT like it is mentioned in other post. If you need a code let me know please, I didn't find any possible clue. -
“I/O operation on closed file” error when trying to open uploaded file django 2.2.12
Unable to open uploaded image when using Django2.2.12, I am facing an error "ValueError: I/O operation on closed file". Type of image is InMemoryUploadedFile Here my code: default_storage.save(uploaded_image.name, uploaded_image) -
How replace an old image for another new image in django models?
I want to replace old image from django models by new image. This is my models.py: class ProfileImage(models.Model): image_id = models.IntegerField(null=True, blank=True) profile_image = models.ImageField(upload_to='images/', null=True, blank=True) -
Django Forms Setting field max_length attribute in __init__() not working
I asked a similar question before regarding this and I currently have a working version that does it another way. However it seems like a lot more code then I need to and I am suppose to be able to set this attribute at init. Here is forms.py def get_automation_form(content, data=None, files=None, initial=None): class AutomationForm(forms.ModelForm): if 'text_field01' in content[1].keys(): text_field01 = forms.CharField(max_length=content[2]['text_field01'], label=content[1]['text_field01']) if 'text_field02' in content[1].keys(): text_field02 = forms.CharField(max_length=content[2]['text_field02'], label=content[1]['text_field02']) if 'text_field03' in content[1].keys(): text_field03 = forms.CharField(max_length=content[2]['text_field03'], label=content[1]['text_field03']) if 'text_field04' in content[1].keys(): text_field04 = forms.CharField(max_length=content[2]['text_field04'], label=content[1]['text_field04']) if 'text_field05' in content[1].keys(): text_field05 = forms.CharField(max_length=content[2]['text_field05'], label=content[1]['text_field05']) if 'text_field06' in content[1].keys(): text_field06 = forms.CharField(max_length=content[2]['text_field06'], label=content[1]['text_field06']) if 'text_field07' in content[1].keys(): text_field07 = forms.CharField(max_length=content[2]['text_field07'], label=content[1]['text_field07']) if 'text_field08' in content[1].keys(): text_field08 = forms.CharField(max_length=content[2]['text_field08'], label=content[1]['text_field08']) if 'text_field09' in content[1].keys(): text_field09 = forms.CharField(max_length=content[2]['text_field09'], label=content[1]['text_field09']) if 'text_field10' in content[1].keys(): text_field10 = forms.CharField(max_length=content[2]['text_field10'], label=content[1]['text_field10']) class Meta: model = Automation fields = content[0] labels = content[1] widgets = { 'color1': ColorWidget, 'color2': ColorWidget, 'color3': ColorWidget, 'color4': ColorWidget, 'color5': ColorWidget, } def __init__(self, *args, **kwargs): super(AutomationForm, self).__init__(data=data, files=files, initial=initial, *args, **kwargs) for key, value in content[3].items(): self.fields[key].required = value # for key, value in content[2].items(): # print(key) # print(type(value)) # self.fields[key].max_length = value # print(self.fields[key]) # print(self.fields[key].max_length) return AutomationForm() At the … -
Django Blog Not all Data being imported
I am currently working on my first django project "not following a tutorial". I'm creating a blog and trying to get all my pictures & post data to import into post. I am getting some info to import, but not all. Specifically, my images and date are not getting populated into post. views.py -------------------------------- def home(request): context= { 'posts' : Post.objects.all(), 'comment': Comment.objects.all(), } return render(request, 'blog/home.html', context) def base(request): return render(request, 'blog/test.html') class ArticleDetailView(DetailView): model = Post template_name = 'blog/standard.html' ------ my html page {% extends 'blog/base.html' %} {% load static %} {% block content %} <section class="main-content"> <div class="padding"> <div class="container"> <div class="row"> <div class="col-sm-8"> <div class="single-post"> <div class="type-standard"> <article class="post type-post"> <div class="top-content text-center"> <span class="category"><a href="categories.html">{{ post.category }}</a></span><!-- /.category --> <h2 class="entry-title"><a href="standard.html">{{ post.title }}</a></h2><!-- /.entry-title --> <span class="time"><time>{{ post.date_posted|date:"F d, Y" }</time></span><!-- /.time --> </div><!-- /.top-content --> <div class="entry-thumbnail"><img src="{post.image.url }"></div><!-- /.entry-thumbnail --> <div class="entry-content"> {{ post.content }} <div class="post-meta"> <span class="comments pull-left"><i class="icon_comment_alt"></i> <a href="#">4 Comments</a></span><!-- /.comments --> <span class="post-social pull-right"> <a href="#"><i class="fa fa-instagram"></i></a> <a href="#"><i class="fa fa-facebook"></i></a> <a href="#"><i class="fa fa-twitter"></i></a> <a href="#"><i class="fa fa-pinterest-p"></i></a> </span><!-- /.post-social --> </div><!-- /.post-meta --> </div><!-- /.entry-content --> </article><!-- /.post --> </div><!-- /.type-standard --> <div class="author-bio … -
how to set a string value as a default value of a float field in django models
i couldn't set a string value as default in a float field here is my code class Product(models.Model): Name = models.CharField(max_length=700, null=True) Price = models.FloatField(null=True) Screen_size = models.FloatField(max_length=300, blank=True ,default="Not mentioned by the seller" , null=True) Focus_type = models.CharField(max_length=300, blank=True ,default="Not mentioned by the seller" , null=True) and when i try to run the code it says ValueError: Field 'Screen_size' expected a number but got 'Not mentioned by the seller'. -
Token Authentication IsAuthenticatedOrReadOnly in Django api
I'm using token to authenticate but I want that people not authenticated can see the content, which means have the GET METHOD. class EstacionViewSet(viewsets.ModelViewSet): queryset = Estacion.objects.all() serializer_class = EstacionSerializer permission_classes = [permissions.IsAuthenticatedOrReadOnly,] filter_backends = (filters.DjangoFilterBackend,) I'm using this kind of views but using this permissions I cant get access to read when I do a GET request. It says that the credentials where not provided which is true but it should be able to read the content of the urls in the api. Do you know a way to implement the ReadOnly if it not authenticated with the token? -
How to create table of forms in Django
Is there a way to create a table of forms in Django? For example. If I had a model: class Decisions(models.Model): meeting = models.ForeignKey(Meeting, on_delete=models.CASCADE) decision = models.TextField(max_length=1000,) decisionDate = models.DateTimeField(default = timezone.now, editable = False complete = models.BooleanField(default = False) I have created a form so that I can edit each individual record of Decisions, but this is time consuming each time I want to edit multiple records. How can I create an html table of forms so that I can edit these records in one view. Something like: <form method="post" enctype="multipart/form-data"> {% csrf_token %} <table> <tr> <th>decision</th> <th>complete?</th> </tr> {% for item in form %} <tr> <td>{{ item.decision }}</td> <td>{{ item.complete }}</td> </tr> {% endfor %} </table> <button type="submit">Update</button> </form> I just don't know where to start with the view creation. Is it best to use a function based view for this? I attempted to use the Class based generic UpdateView but it requires a pk to know what record it is editing, and in my case it is many. Any guidance is appreciated! Thanks -
Django change default hash algrithm to sha256
I wanna authme minecraft plugin integration with django app and my question is "how to change django hash algorithm to pure sha256" -
How do I override the results from an django API query
I'm very new to Django, so this might seem basic. I have 2 models: class Brand(models.Model): brand_name = models.CharField() class Foo(models.Model): brand = models.ForeignKey(Brand, null=True) foo_name = models.CharField() Foo.brand can be null. Now when an API query is made on Foo, I want to include results where the brand's name matches but also where Foo.brand is null If Foo looks like this: Foo.brand, Foo.foo_name 1, "apple" 3, "orange" 1, "mango" null, "grape" /api/foo?brand=1 should return apple, mango and grape. How can I get this? I tried reading similar questions, it sounds like I need to override the viewset, but wasn't sure. Thanks. -
Exception when running Django 2.2 runserver using python 3.7.4
Exception happened during processing of request from ('127.0.0.1', 65512) Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 650, in process_request_thread self.finish_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 360, in finish_request self.RequestHandlerClass(request, client_address, self) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 720, in init self.handle() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 171, in handle self.handle_one_request() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 179, in handle_one_request self.raw_requestline = self.rfile.readline(65537) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 589, in readinto return self._sock.recv_into(b) ConnectionResetError: [Errno 54] Connection reset by peer -
Django To remove quotation marks
I made a simple web page using the Django. I get the data from mysql, and mysql db. There are always quotation marks ' at the beginning and at the end. I want to remove quotation marks and display the values. Do I need to modify views.py? Or should I modify html? Please tell me how to get rid of the quotation marks Thank you for your reply in advance. my views from django.shortcuts import render from django.http import HttpResponse from .models import Macro # Create your views here. def cmacroMacro(request): macro_data = Macro.objects.get(pk=request.GET.get('pk',1)) context = {'macro_data':macro_data} return render(request, 'macrof/registerMacro.html', context) my html <div>contents</div> <textarea cols="70" id="contents" placeholder="본문내용">{{ macro_data.contents }}</textarea> <div>review</div> <textarea cols="70" id="review" placeholder="상품평">{{ macro_data.review }}</textarea> <div>link</div> <textarea cols="70" id="link" placeholder="쿠팡링크">{{ macro_data.link }}</textarea> my models.py contents = models.CharField(max_length=500) product_i = models.CharField(max_length=1000) review = models.CharField(max_length=10000) link = models.CharField(max_length=500) -
Django allauth: Remove form label from inherited form field?
Problem I'm building a registration page using Django with allauth. I am trying to remove the 'E-mail' label from the email field. What I've tried I've removed the labels from First Name and Last Name by adding label='' to their fields (as was recommended in similar questions). For some reason, this is not working for the email field. My forms.py: class CustomSignupForm(SignupForm): first_name = forms.CharField(max_length=30, label="", widget=forms.TextInput(attrs={'placeholder': 'First Name'})) last_name = forms.CharField(max_length=30, label="", widget=forms.TextInput(attrs={'placeholder': 'Last Name'})) email = forms.EmailField(label='', widget=forms.TextInput(attrs={'placeholder': 'Email'})) def signup(self, request, user): user.first_name = self.cleaned_data['first_name'] user.last_name = self.cleaned_data['last_name'] user.email = self.cleaned_data['email'] user.save() return user I've also tried: email = forms.EmailField(label='', widget=forms.TextInput(attrs={'type': 'email', 'placeholder': 'E-mail address'})) Below is the allauth forms.py that the form is inheriting from: class BaseSignupForm(_base_signup_form_class()): username = forms.CharField(label=_("Username"), min_length=app_settings.USERNAME_MIN_LENGTH, widget=forms.TextInput( attrs={'placeholder': _('Username'), 'autofocus': 'autofocus'})) email = forms.EmailField(widget=forms.TextInput( attrs={'type': 'email', 'placeholder': _('E-mail address')})) def __init__(self, *args, **kwargs): email_required = kwargs.pop('email_required', app_settings.EMAIL_REQUIRED) self.username_required = kwargs.pop('username_required', app_settings.USERNAME_REQUIRED) super(BaseSignupForm, self).__init__(*args, **kwargs) username_field = self.fields['username'] username_field.max_length = get_username_max_length() username_field.validators.append( validators.MaxLengthValidator(username_field.max_length)) username_field.widget.attrs['maxlength'] = str( username_field.max_length) default_field_order = [ 'email', 'email2', # ignored when not present 'username', 'password1', 'password2' # ignored when not present ] if app_settings.SIGNUP_EMAIL_ENTER_TWICE: self.fields["email2"] = forms.EmailField( label=_("E-mail (again)"), widget=forms.TextInput( attrs={ 'type': 'email', 'placeholder': _('E-mail address confirmation') } … -
Changing from int:pk to Slug
After finalizing my blog project I found out a way a switch from writing the id of the blog to writing a function to add the post title to become a slug. So I am currently trying to switch all my post detail to slug but after I finished everything I am getting a page error 404 which doesn't indicate exactly where I have something wrong with my code. My question is when I move from changing the urls from int:id to slug what should I be looking for to change as well to avoid page error 404? In the URL for every page detail I am getting the int:id not the title of the post and the error 404 I have commented the addition of the slug function: Here is the models.py : class Post(models.Model): designer = models.ForeignKey(User, on_delete=models.CASCADE) title = models.CharField(max_length=100) likes = models.ManyToManyField( User, related_name='liked') slug = models.SlugField(blank=True, null=True, max_length=120) def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(self.title) super(Post, self).save(*args, **kwargs) Here is the views.py class PostDetailView(DetailView): model = Post template_name = "post_detail.html" def get_context_data(self, *args, **kwargs): context = super(PostDetailView, self).get_context_data() stuff = get_object_or_404(Post, id=self.kwargs['slug']) total_likes = stuff.total_likes() liked = False if stuff.likes.filter(id=self.request.user.id).exists(): liked = … -
Target WSGI scriptcannot be loaded as Python module
I am looking for some help in migrating a web app from local machine to apache server. -Python 3.7 -Django 2.1 -Apache 2.4 I also have a virtualenvironment created for the FleetManagRApp. My httpd.conf looks like this. LoadFile "c:/python36/python36.dll" LoadModule wsgi_module "c:/python36/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd" WSGIPythonHome "c:/python36" Listen 9981 <VirtualHost *:9981> WSGIScriptAlias / "E:/DjangoSite/WebApps/WebApps/wsgi.py" Alias /static "E:/DjangoSite/WebApps/FCApp/static" <Directory "E:/DjangoSite/WebApps/FCApp/static"> Require all granted </Directory> <Directory "E:/DjangoSite/WebApps/WebApps"> <Files wsgi.py> Require all granted </Files> </Directory> </VirtualHost> Listen 3456 <VirtualHost *:3456> path="E:/FleetManagRDjango/FleetManagRApp/" WSGIScriptAlias / "E:/FleetManagRDjango/FleetManagRApp/FleetManagRApp/wsgi.py" Alias /static "E:/FleetManagRDjango/FleetManagRApp/PMApproval/static" <Directory "E:/FleetManagRDjango/FleetManagRApp/PMApproval/static"> Require all granted </Directory> <Directory "E:/FleetManagRDjango/FleetManagRApp/FleetManagRApp"> <Files wsgi.py> Require all granted </Files> </Directory> </VirtualHost> wsgi.py looks like below import os import sys path = 'E:/FleetManagRDjango/FleetManagRApp' # use your own username here if path not in sys.path: sys.path.append(path) from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'FleetManagRApp.settings') application = get_wsgi_application() Error Log mod_wsgi (pid=21464): Target WSGI script 'E:/FleetManagRDjango/FleetManagRApp/FleetManagRApp/wsgi.py' cannot be loaded as Python module. mod_wsgi (pid=21464): Exception occurred processing WSGI script 'E:/FleetManagRDjango/FleetManagRApp/FleetManagRApp/wsgi.py'. Traceback (most recent call last):\r File "c:\\python36\\lib\\site-packages\\django\\db\\utils.py", line 115, in load_backend\r return import_module('%s.base' % backend_name)\r File "c:\\python36\\lib\\importlib\\__init__.py", line 126, in import_module\r return _bootstrap._gcd_import(name[level:], package, level)\r File "<frozen importlib._bootstrap>", line 994, in _gcd_import\r File "<frozen importlib._bootstrap>", line 971, in _find_and_load\r File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked\r File "<frozen importlib._bootstrap>", … -
when I use http://dev.example.com with django-sites framework, do I need to create all subdomains inside site?
I was Testing django-sites framework, do I need to create a site for the full address? I have tried inserting only example.com in sites then if I try dev.example.com is not working. is It right? -
Django - load JSON file in template using CDN and access it's values
I am developing a django app, I need to load some values off a json file that is served on with CDN. I would like to load it on the template so I can use Template fragments caching. Given the url cdn.domain.theroutetothisfile/file.json. The file is updated every 48 hours. I need to access some values on this json file, description something similar to: <P>{{file.description}}</p> #where file is the loaded json Searched for hours with no luck. -
create RadioSelect form django
I am new in django, I am trying to create a form with many input (text, date...). For radioSelect, I used the code below : from django import forms class myForm(forms.Form): gender= [('W', 'Women'),('M', 'Man')] gender= forms.CharField(label='Gender :', widget=forms.RadioSelect(choices=gender)) I got the following result : result code I am trying to have this radioSelect in one row ==> something like : desired format How can I make this with form django please ? -
How to select manually choices with django-multiselectfield without using django froms
I'm using django-multiselectfield like that : #models.py weekdays = MultiSelectField(choices=DAYS_OF_WEEK_CHOICES, max_length=11, null=True, blank=False) my question it's possible to select or deselect manually the choices from the DB wihtout using django forms ? By using something like that or else in views.py: obj = something.objects.get(id=5) obj.weekdays.set("Sunday") obj.save() -
Django GenericForeignKey relation
I am trying to create a bookmark system using Django ForeignKey's I was wondering how I can add different objects to the Bookmark Model, (Post, Comment, ...) so that a user can see all object that they bookmarked. Currently my bookmarks model is like: class Bookmarks(models.Model): user = models.ForeignKey(Profile, on_delete=models.CASCADE,related_name='bookmarks') date = models.DateTimeField(auto_now_add=True) content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) object_id = models.PositiveIntegerField() content_object = GenericForeignKey() And for instance this is my Post model: class Post(models.Model): title = models.CharField(max_length=100) content = models.TextField(validators=[MaxLengthValidator(1200)]) author = models.ForeignKey(Profile, on_delete=models.CASCADE) How can I for instance add a post object to user with id=23 to that user's bookmarks? I do not know how to add and retrieve objects for a user. How can I achieve this? -
I am trying to put a related table's data into a list serializer in Django Rest Framework
I have two models: class Settings(models.Model): user = models.ForeignKey( User, on_delete=models.CASCADE) simplified = models.BooleanField() audio_download = models.BooleanField() show_read = models.BooleanField() show_pinyin = models.BooleanField() char_size = models.IntegerField() pinyin_size = models.IntegerField() start_date = models.DateField(null=True) end_date = models.DateField(null=True) class Meta: db_table = 'settings' class HSK(models.Model): settings = models.OneToOneField( Settings, on_delete=models.CASCADE) hsk1 = models.BooleanField() hsk2 = models.BooleanField() hsk3 = models.BooleanField() hsk4 = models.BooleanField() hsk5 = models.BooleanField() hsk6 = models.BooleanField() hskplus = models.BooleanField() I want my JSON returned by my GET request to look this like: { simplified: true, audio_download: true, ..., hsks: { hsk1: true, hsk2: true, hsk3: false } } My GET request looks like this: def get(self, request, user_id): settings_saves = Settings.objects.select_related( "hsk").filter(user_id=user_id) serializer = SettingsSerializer(settings_saves, many=False) return Response({"settings": serializer.data}) And my serializer looks like this: class SettingsSerializer(serializers.Serializer): user_id = serializers.IntegerField() simplified = serializers.BooleanField() audio_download = serializers.BooleanField() show_read = serializers.BooleanField() show_pinyin = serializers.BooleanField() char_size = serializers.IntegerField() pinyin_size = serializers.IntegerField() start_date = serializers.DateField() end_date = serializers.DateField() hsk1 = serializers.BooleanField(source="hsk.hsk1") hsk2 = serializers.BooleanField(source="hsk.hsk2") hsk3 = serializers.BooleanField(source="hsk.hsk3") hsk4 = serializers.BooleanField(source="hsk.hsk4") hsk5 = serializers.BooleanField(source="hsk.hsk5") hsk6 = serializers.BooleanField(source="hsk.hsk6") hskplus = serializers.BooleanField(source="hsk.hskplus") hsks = serializers.ListField( child=serializers.BooleanField(), source="hsk") I can get all of the fields individually: { "settings": { "user_id": 1, "simplified": true, "audio_download": true, "show_read": true, "show_pinyin": true, …