"Вопросы и ответы" Django и Python

28.05.2025
Django manage.py Command KeyboardInterrupt cleanup code execution

Do you have an idea how to use signals in custom management commands in Django? My Command's handle method processes continious stuff which needs to be cleaned up, when Command is interrupted. Without any specific additional signal handling, my Command …

28.05.2025
Working in django with data with a saved history of changes

I am creating an information system in which some entities have separate attributes or a set of them, for which it is necessary to store a history of changes with reference to the date of their relevance for further processing …

28.05.2025
Why postgres service if If you buy a managed PostgreSQL database from DigitalOcean?

Why do we need to add postgres service if we buy postgress database on DigitalOcean ? For me there is two ways to setup our database : Solution 1 : Let docker handle it by taking advantage of docker …

28.05.2025
How to handle unfamiliar real-time tasks in Django projects without proper documentation? [closed]

We’re working with backend developers who frequently encounter real-time tasks that fall outside their core experience—for example, integrating Django applications with older third-party systems (e.g., SOAP-based services, custom XML APIs) or poorly documented internal tools. A common issue involves connecting …

27.05.2025
ModelViewSet does not overwrite DEFAULT_PERMISSION_CLASSES'

Hello I'm working on making all urls requires user to be authenticate , but some urls i want them to be accessible by public, so i use permission_classes = [AllowAny] and authentication_classes = ([]) to overwrite default configurations …

27.05.2025
How can I organize the structure of entering the city/restaurant tables of the Django database?

Good day! I have a plan for the database structure. An example is in the figure below. For example, I have - all coffee shops - within one region - state or several regions. In one city there are several …

27.05.2025
Update LANGUAGE_CODE in Wagtail before internationalization?

I've developed a site in Wagtail, but missed to update the LANGUAGE_CODE before the first (and several other) migrations. In the Internationalization instructions the following is noted: "If you have changed the LANGUAGE_CODE setting since updating to …

26.05.2025
Low RPS when perfomance testings django website

I have a code like this that caches a page for 60 minutes: import os import time from django.conf import settings from django.core.cache import cache from django.core.mail import send_mail from django.contrib import messages from django.http import FileResponse, Http404, HttpResponse from …

26.05.2025
Django Admin site css not loading so site is lokking broken

I am using django's admin site and in that css is not loadung so site is looking totally broken.In last 3-4 days i almost tried everything which is available around the web to fix it but its not getting fixed. …

26.05.2025
Problems integrating Django and Tableau with Web Data Connector (WDC)

I’m working on a project where I need to integrate data from my Django application into Tableau using a Web Data Connector (WDC). However, I’m running into several issues and would appreciate any help or guidance from the community. Setup: …

26.05.2025
Unexpected behaviour with django with django channels

Class SessionTakeOverAPIView(generics.GenericAPIView): """ This API view allows a human or AI to take over a chat session. The view handles session takeover validation, updates the session state, and broadcasts relevant events to the chat group. A POST request is used …

26.05.2025
How to use schema with variable to pass though different environnement

I try to variabilise schema name because i use different environnment for my project. So i do this in my models.py: # from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser #Pour plus d'information sur le fonctionnement des …

26.05.2025
How can I send data via copy paste operation in Django Views or model?

I have such a very difficult problem. Which is very specific and not easy to enter data. I am thinking how to send data to the database or, as an option, just send data to the code in the internal …

26.05.2025
Suds throwing exception on "type not found"

We are using SUDS v1.1.1 and recently starting getting a "Type not found" exception as the response to a request contains a field not in the wsdl. I tried initializing the client with the strict keyword as follows but the …

25.05.2025
Django Rest Framework Cursos pagination with multiple ordering fields and filters

I have an issue with DRF, CursorPagination and Filters. I have an endpoint. When I access the initial page of the enpoint I get a next URL "next": "http://my-url/api/my-endpoint/?cursor=bz0yMDA%3D&date__gte=2025-04-25T10%3A00%3A00Z&date__lte=2025-04-26T10%3A00%3A00Z" When I access this URL I get a previous URL …

25.05.2025
PYTHON FACIAL RECOGNITION (OPEN CV + FACE_RECOGNITION) [closed]

I need some help with a project I'm working on. I currently have a Python script that performs facial recognition using OpenCV and the face_recognition library. The script works fine in standalone Python, but now I need to transform it …

24.05.2025
Setup dj_rest_auth and all allauth not working

Hello i'm trying to setup dj_rest_auth and allauth with custom user model for login for my nextjs app but it seems not working the backend part besides it not working i get this warning /usr/local/lib/python3.12/site-packages/dj_rest_auth/registration/serializers.py:228: UserWarning: app_settings.USERNAME_REQUIRED is deprecated, use: …

24.05.2025
Django's manage.py dumpdata adds free text to each file

I am trying to move Django data from SQLite to Postgres, following this flow: SQLite connection in settings.py manage.py dumpdata > data.json Postgres connection in settings.py manage.py loaddata data.json It seems to be sort of working (still struggling with …

24.05.2025
Django ModelFormset_Factory issue with rendering form

I've reviewed other questions and answers, worked through the django documentation and followed tutorials but I can't get my model formset to render correctly. So far, I have the following working fine: forms.py class BulkUpdateForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(BulkUpdateForm, …

24.05.2025
Debugging django admin 403 Forbidden error

I am trying to access django admin with my credentials. No matter whether the credentials are correct or not I just keep geeting 403 forbidden with the reason "CSRF cookie not set". Using chrome dev tools I can clearly see …

23.05.2025
Django admin drop down based on object open

I would like to use admin to do a lot of the heavy lifting in an application im building. I require the field icon in admin_navigation to be filtered by business that is in view. for example: icon.objects.filter(business = self.business.id) …

23.05.2025
Django: dependencies reference nonexistent parent node creating a custom user

I am learning Django this is just a personal and local project. In the middle of development I decided to change my user to a CustomUser that I created with AbstractUser. When typing python manage.py makemigrate I got this error: …

23.05.2025
Company with many different names

I have the following situation that looks simple, but I do not know how to make models for it :( Here is what I have. Model Company that contains only description (field note) class Company(models.Model): note = models.TextField(_('note'), blank=True, null=True) …

23.05.2025
Django and IIS, handlers not functioning as expected

I have been working on developing an internal website for my company, I am using django as the framework. Once I went through the process of moving everything to IIS I lose my css files for the admin page. I …

23.05.2025
How can I connect multiple model tables Django for data import export?

I have three 3 Django model tables. They are kind of connected to each other so that each row, each line from one model table corresponds to the same from another model table. You could say that I'm just splitting …

23.05.2025
Python manage.py tailwind install seems to run in wrong directory

I installed Django-tailwind according to the documentation but am now facing an issue when trying to python manage.py tailwind install. The theme app was created successfully and contains a package.json file. npm is found since i specified …

22.05.2025
Как в шаблоне Dajngo поставить условие в цикле For?

Нужно в каждой строчке таблицы шаблона выводить только связанные записи из второй таблицы: Во Views выглядит вот так def orders(request): orders = Order.objects.order_by('date') orderitems = OrderItem.objects.all() return render(request, "orders/orders/orders.html", {'orders': orders, 'orderitems': orderitems}) В самом шаблоне вот так …

22.05.2025
Okta Redirection based on attribute then access SubPage

I have a successfully authenticated and got redirected to my role let's say Admin page, in my Okta it is called http://test.com/myAdmin I have other redirects depending on the users roles; however, that those work as well …

22.05.2025
Slow performance with Django admin model page [closed]

I have a problem with a change view of an model in Django. I have profiled the endpoint with different tools, and also took logs of the database queries run using shell plus. I can't see any long calls on …

22.05.2025
DigitalOcean App Platform does not parse ${db.DATABASE_URL} after bulk editor changes

I am using DigitalOcean App Platform to deploy a Django app. The initial deployment worked fine, but I've attempted to use the bulk editor on the component-level environment variables, and since then, the deployment fails when executing dj_database_url.config(default=config('DATABASE_URL'). For debugging, …

21.05.2025
Passing Arguments to Django Views From a Rendered Page

I've been tasked to build web-based front end to an existing MySQL database. I'm new to web development in general, decided to use Django because I'm a pretty advanced Python user. However, I'm completely stuck doing what seems like it …

21.05.2025
Django annotate with ExtractMonth and ExtractYear doesnt extract year

I have this model: class KeyAccessLog(models.Model): key = models.ForeignKey( Key, related_name="access_logs", on_delete=models.CASCADE ) path = models.CharField(max_length=255) method = models.CharField(max_length=10) ip_address = models.GenericIPAddressField() created = models.DateTimeField(auto_add_now=True) class Meta: verbose_name = "Key Access Log" verbose_name_plural = "Key Access Logs" ordering …

21.05.2025
Custom id generation on bulk_create in django

I want different models in my django project to have different prefixes (like usr_ for user, acc_ for account etc.) I then want to append a nanoid to this prefix. I defined a basemodel which is used by all the …

21.05.2025
How can I link multiple Django model tables as if they were one when entering data?

Good morning! I am a bit new to Django. I wanted to ask about the relationships between Django model tables. I have several Django model tables. They should all belong to the same correspondence - a row from one table …

21.05.2025
Could not find backend 'storages.backends.s3boto3.S3StaticStorage'

When deploying my Django app it just (seems like) stopped to connect to my S3 bucket. The full message I get when running collectstatic is Traceback (most recent call last): File "/home/ubuntu/campmanager/manage.py", line 22, in <module> main() File "/home/ubuntu/campmanager/manage.py", line …

21.05.2025
Использование функции footerCAllback в сторонних плагинах( у меня Flyon UI)

Не могу использовать функцию footerCallback в datatable от Flyon UI , имеется такая ошибочка Uncaught TypeError: Cannot read properties of undefined (reading 'push') но кажется не только из-за нее {% load django_vite %} {% block title %} Отчет …

21.05.2025
React front_end & Django back_end Login functionality

I created react front end first then i create a django app and project for back end in the front end back end connected by Django REST framework and jwt and serializers the django back_end and api can send a …

21.05.2025
Updated from Django 3.2 to 5.2, now I'm getting "Obj matching query does not exist"

I'm using Django in a non-Django project (Postgresql 17 under the hood) purely to make my unit tests easier. I've defined all my models like this: class Bar(models.Model): internal_type = models.TextField(...) ... class Meta: managed = False db_table = 'myschema\".\"bar' …

20.05.2025
I'm trying to integrate Google SSO into my Django app, but I keep running into an issue

I'm 99% sure it has to do with my custom authentication model, as shown below: from django.contrib.auth.backends import ModelBackend from django.contrib.auth import get_user_model from django.db.models import Q UserModel = get_user_model() class UsernameOrEmailBackend(ModelBackend): def authenticate(self, request, username=None, password=None, **kwargs): try: …

20.05.2025
How to get a moving average (or max) in time period using Django ORM

I am trying to work out if it's possible/practical to use the Django ORM to get the highest value in an arbitrary timebox out of the database. Imagine a restaurant orders ingredients every day, we might have a simple model …