Django 2.2 cannot serialize default values once migration has been done

I have a model which is refered to as a foreignkey with on_delete set to SET_DEFAULT. Because of that, I need to provide this model with a default item. I created a static method which does just that. …

Django order a query by instance of ManyToMany

I have a model A with a ForeignKey to B: class A(models.Model): b = models.ForeignKey(B, on_delete=models.CASCADE) A ManyToMany relationship with an extra field that weight any B and C relation: …

Django Error: Field ‘id’ expected a number but got ‘list’

I have an app with 2 models and I’m trying to create a List View and a Detail View. The list view worked fine, but when I created the detail view the list view stopped working and it’s prompting me …

How can I get a value from other model, based in other value from that same other model?

How can I get the proper “sumvalue” in the example? (which I only know how to represent in SQL): class Addition(models.Model): location = models.ForeignKey(Place, …) a = models….

Showing all the users who have set their country same as request.user

I am building a BlogApp and I am trying to show all the users which set their Countries similar to request.user. For Example : If user_1 is request.user and selected state choice Victoria and country …

Django add custom permission

I am facing the problem of adding custom permission in Django. My idea is that when authorizing a user, if it belongs to group1, only the rows of group1 are displayed, and otherwise the rows of group2….

ordering modelchoicefield in django loses formatting

I wanted to order a list in my form view, and found this post here: How do I specify an order of values in drop-down list in a Django ModelForm? So I edited my code and added the line specialty = …

How to cache individual Django REST API POSTs for bulk_create?

I have a Django REST API endpoint. It receives a JSON payload eg. { “data” : [0,1,2,3] } This is decoded in a views.py function and generates a new database object like so (pseudo code): …

How to list the titles of html pages with links on the home page in Django

Picture of my window I am sorry if this is a stupid question but I am new to Django. I am building a website and I have articles saved as template files. I want to display all of their titles with …

Django: How to use data from a function as a field in Meta class

I’ve created a function in my serializers.py that call an external API and give me a dict back. How can I use the output from return downloads in the get_all_files as a field in class Meta? After the …