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 Australia and then user_2 registered and set the same state Victoria and country Australia. So i want to show …
Tag: django
Add custom button near Save button Django-admin
I have added a custom button in django admin, however its below the Save and Save and Close buttons, how can I make this custom button on the same line with the 2 buttons above, below is the image: Then, how I overridden the button with the templates: Answer Django has a <div class=”submit-row”…
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. There is a group field in the database table, it contains only two values group1 and group2. In the admin pa…
django custom Func for specific SQL function
I’m currently performing a raw query in my database because i use the MySQL function instr. I would like to translate is into a django Func class.I’ve spend several days reading the docs, Django custom for complex Func (sql function) and Annotate SQL Function to Django ORM Queryset `FUNC` / `AGGRE…
Django list_display highest value ManyToMany Field
I want to know how I can display the “highest value” from my ManyToMany Field in the admin. This is my models.py file: In my backend, I have created different types of Degree’s, all with a “ranking”. In my case, the highest degree you can have is “Doctoral Degree”, wi…
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 = forms.ModelChoiceField(queryset =’…’) So then I reload the form and the widget is all smoshed an…
How to cache individual Django REST API POSTs for bulk_create?
I have a Django REST API endpoint. It receives a JSON payload eg. This is decoded in a views.py function and generates a new database object like so (pseudo code): In tests, it is 20x faster to create a list of x1000 newobjs, then do a bulk create: So, the question is how to save individual POSTs somewhere in…
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 links directed to those templates but I want to automatically list them so if I add a new template
Can’t login my users, they don’t seem to be registering properly
I’m trying to login the users I registered in my registration view (where I get a 200 code that says POST request was successful) but I get “Unable to log in with provided credentials.” when I try to log them in. When I check in the shell with User.objects.all(), I only get my superuser back…
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 first answer, I’ve got the following error message: Line 68 is the following: return get_all_files…