43,695 questions
0
votes
2
answers
53
views
Django Summernote: How to delete attachment files from server when removing them from admin?
When I delete a file from the Attachment model (which is provided by django-summernote), the record is removed from the database, but the actual file remains on the server.
I want to make sure that ...
2
votes
2
answers
67
views
Django REST project doesn’t detect apps inside the “apps” directory when running makemigrations
I have a Django REST project where I created a directory called apps to store all my apps.
Each app is added to the INSTALLED_APPS list in my settings file like this:
INSTALLED_APPS = [
'django....
0
votes
0
answers
73
views
'django.db.utils.ProgrammingError: relation "users_user" does not exist' error while running ' python manage.py migrate_schemas --shared'
AccrediDoc - Multi-tenant Accreditation Management System
A comprehensive Django-based multi-tenant accreditation management system designed for healthcare organizations in India. Manage NABL, NABH, ...
1
vote
2
answers
93
views
How to reuse a Django model for multiple relationships
I want to make a task model and a user model. And I want each task to be able to be related to 3 users. Each task should be related to a creator user, an assignee user, and a verifier user. And I want ...
1
vote
1
answer
99
views
Custom Permissions in django-ninja which needs to use existing db objects
I am using django-ninja and django-ninja-extra for an api.
Currently I have some Schema like so
from ninja import schema
class SchemaA(Schema)
fruit_id: int
other_data: str
and a controller ...
0
votes
1
answer
99
views
How to reset password in a Django UserChangeForm
I have a basic CustomUser model in my project. When I want to update it I fill my form with instance where I try to make user's password null, but anyway in the form I receive:
"No password set.
...
2
votes
3
answers
112
views
Query Django Users by get_username method
I am trying to get the Django User object with a specific username. The obvious way to do it is like this:
from django.contrib.auth.models import User
bob = User.objects.get(username="Bob")
...
0
votes
1
answer
52
views
Django model with FK to learner app model Group is displaying options from user admin Group
I have the following models:
learner app
class Group(models.Model):
short_name = models.CharField(max_length=50) # company acronym
slug = models.SlugField(default="...
2
votes
1
answer
56
views
Multiple Data Entry in Django ORM
I have been trying to create a way that my Django database will store data for 7 consecutive days because I want to use it to plot a weekly graph but the problem now is that Django doesn't have a ...
1
vote
1
answer
62
views
CheckConstraint in Django model not triggering in unittest.TestCase (AssertionError: IntegrityError not raised)
I have a Model class with a series of constraints that I am attempting to test, and I am unable to get these constraints to return an IntegrityError in testing. The class is as follows:
from django.db ...
0
votes
1
answer
56
views
Custom Connection usage in graphene_django
I have a variation of the problem described here:
Using DjangoFilterConnectionField with custom Connection in graphene_django
The modified problem is as follows:
Lets say I have a Django model class '...
0
votes
2
answers
221
views
Managing Django groups and permissions for custom users
For my Django projects, I am used to creating a custom user model and managing what my user can do for a specific route using a roles field like this:
class User(AbstractBaseUser, PermissionsMixin):
...
0
votes
1
answer
86
views
Django REST API endpoints URL paths
I have a Django 4.2 app with Postgres DB and REST API. My urls.py contains this path in urlpatterns:
path('create/<int:pk>/<str:name>/', ComponentCreate.as_view(), name='create-component')
...
1
vote
1
answer
47
views
Validating admin form data of a ManyToManyField in Django
In Django, I have a ManyToManyField relation to another Table. It is shown as expected as a multi-select list in the admin UI.
class Host(models.Model):
groups = models.ManyToManyField(
'...
2
votes
1
answer
44
views
Django ORM, seeding users and related objects by OneToOneField
I am designing a django application for educational purposes.
I've come up with creating a fake banking application.
The idea is to have a User<->BankAccount link by a OneToOneField.
Similarly, ...
0
votes
1
answer
77
views
How to prevent Django from generating migrations when using dynamic GoogleCloudStorage in a FileField?
On my Django Project I have a model that a property is used to store videos in a specific and single Google Cloud Storage bucket, using FileField.
The model is defined like this:
from storages....
0
votes
0
answers
61
views
django-import-export id auto generated by the package during insert?
I'm using django-import-export and trying to work it with multi-thread concurrency.
I tried logging the sql queries and notice that INSERT query has id values generated as well.
*EDIT: First there's a ...
0
votes
0
answers
39
views
Django-tenants: relation "journal_nav_topnavitem" does not exist even after adding app to SHARED_APPS and running migrate_schemas --shared
I'm working on a multi-tenant Django project using django-tenants with Django 3.2.16. I created an app called journal_nav and initially added it only to TENANT_APPS. Later, I moved it to SHARED_APPS ...
1
vote
1
answer
50
views
Django cannot create record with correct foreign key to CharField with spaces in middle - getting surrounded by single and double quotes like "'a a'"
First of all - I understand that CharField is rather bad primary key, but it's unique in-game name, good 2 use as-is in many places, and may contain spacees. And IMHO the problem will repeat with non ...
1
vote
1
answer
46
views
How to use Django Q objects with ~Q() inside annotate(filter=...) to exclude a value?
I'm refactoring a legacy Django Job to use annotate with filtered Count aggregations instead of querying each record individually (avoiding the N+1 problem).
I want to count the number of related ...
1
vote
1
answer
71
views
How to support multiple Google Cloud Storage buckets in a Django FileField without breaking .url resolution?
I'm using Django with django-storages and GoogleCloudStorage backend.
My model has a FileField like this:
raw_file_gcp = models.FileField(storage=GoogleCloudStorage(bucket_name='videos-raw'))
At ...
2
votes
1
answer
48
views
I tried to implement custom validation error in django
I have wrote this validators.py file:
from django.core.exceptions import ValidationError
import os
def allow_only_images_validator(value):
ext = os.path.splitext(value.name)[1]
print(ext)
...
1
vote
1
answer
47
views
How can I split the two forms so that only one of the two forms in the template is processed?
I am trying to place two independent forms on one template.
I have them placed but there is a problem that both forms are being checked.
Validation of both forms is being checked. Although I only have ...
1
vote
1
answer
22
views
How can I filter values from one model and insert the result into the form as choices?
Good day!
I have two tables - models.
I fill them gradually.
First I have the first table.
First I enter data into the first table.
And there - in the first table I have - repeating data.
Field - (...
0
votes
2
answers
79
views
How to update removed model choices in Django without breaking existing database values?
I'm working on a Django project where we use models.TextChoices for fields like current_status. Our client requested wording updates — for example, renaming "Contacted" to "Contacted ...
0
votes
0
answers
31
views
How can I load values into the form from the desired table row by clicking?
Good day! I plan to build a mini application. Which consists of one page (the main one) - a template.
And also one secondary page - on the second page I fill in information into the model table ...
1
vote
1
answer
44
views
How to pass pk to form (ForeignKey) and views - from template when following link?
How to pass pk to the form (ForeignKey) and views - from the template when clicking on a link?
Good day!
I have a model.
Which is displayed in the template.
And the transition to another template is ...
0
votes
1
answer
55
views
How to select from the second field in the form - filtering data depending on the values of the first field?
Is it possible to somehow adapt something similar to my problem?
I would like a list to appear in the form based on data from another list
Select from the second field - filtering data - (contents) ...
3
votes
1
answer
78
views
Django/PostgreSQL: Unique constraint with a dynamic condition like expires_at > now()
I'm building a secure OTP system in Django. The model looks like this:
class OTP(models.Model):
MAX_ATTEMPTS = 3
DEFAULT_EXPIRE_IN_MINUTES = 1
class Purposes(models.IntegerChoices):
...
0
votes
1
answer
65
views
How can I set up filtering in the form model of one field based on another when selecting?
I have 2 model tables.
In the first table I have a form in the set in which there is one interesting field.
This field can have the same values.
If we consider the second table model - then in the ...
2
votes
1
answer
67
views
How can I configure the wrapping of a large long line of text in a form Django?
I have a form with OneToOneField where data is loaded from another table model.
But I often have large data sizes there and the displayed text does not fit into the window size.
Is it possible to ...
0
votes
1
answer
42
views
Django Multi-Database ValueError: "Cannot assign Role object: the current database router prevents this relation"
I'm encountering a ValueError in my Django application when trying to save a User object with a related UserRoleAssociation in the admin interface. The error occurs in a multi-database setup where ...
2
votes
1
answer
95
views
How do I write a Django ORM query that returns a match based on an intersection of lists?
If I have, for example:
from django.contrib.postgres.fields import JSONField
class MyModel(models.Model):
data = JSONField()
GIVEN a model instance obj1, where data == ['apple', 'banana', '...
1
vote
1
answer
39
views
How can I fill in related models separately through forms (OneToOneField)?
I have two table models.
I write data to one of them using a form.
I also want to write data to the other model table using a form.
But I'm trying to link these tables.
Use the first one as a base.
...
0
votes
1
answer
66
views
How do I prevent a user from creating multiple objects within 24 hours in Django
I'm trying to prevent users from creating more than one Mining object within a 24-hour period in my Django project. I chose to use Django signals, specifically the pre_save signal, to enforce this ...
1
vote
1
answer
46
views
'User' object has no attribute 'profile' - Django profile update problem
I am new to Django and currently learning and I have encountered a problem that I just can't seem to solve.
from django.shortcuts import render, redirect
from django.contrib import messages
from ....
0
votes
1
answer
97
views
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 ...
-3
votes
1
answer
101
views
How can I organize the structure 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.
I am trying to make a ...
1
vote
1
answer
112
views
How to solve this migrate error in django?
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....
0
votes
1
answer
63
views
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 ...
0
votes
1
answer
49
views
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 ...
1
vote
1
answer
48
views
Do you see any circular imports
I am getting this error with DRF, django.core.exceptions.ImproperlyConfigured: The included URLconf and I can not find the cause of it. My urls.py is afaiK configured correctly, so I'm looking for ...
0
votes
0
answers
42
views
Django django-admin-async-upload returns 302 redirect to 404 page in staging environment
I'm using the django-admin-async-upload library to handle asynchronous file uploads in my Django project. Everything works perfectly in my local development environment.
However, when I deploy to the ...
0
votes
0
answers
36
views
How to handle existing data when introducing an intermediate model between a base model and a child model in a Django Polymorphic inheritance hirarchy
Current models:
class Task(PolymorphicModel):
pass
class DownloadTask(Task):
pass
New models:
And now i want to do add a new layer called VirtualTask:
class Task(PolymorphicModel):
pass
...
0
votes
0
answers
69
views
Vehicle records for auto parts application
I'm trying to figure out how to create a vehicle filter for an auto parts application for a client. They want their customers to be able to filter by Year, Make, Model, Trim and Engine.
We're using ...
2
votes
2
answers
148
views
What are the downsides of default ordering by PK in Django?
Django models support default ordering, via Meta.ordering. What are the downsides to putting ordering = ["pk"] on my base model?
In particular, I'm curious about the performance impact. ...
1
vote
1
answer
49
views
Specific permissions for different types of users with django rest framework model and view
I'm using DRF's ModelViewSet for my views and DefaultRouter to create the urls.
This particular model creates a feature that only admins have full CRUD access.
Authenticated users should have READONLY ...
0
votes
0
answers
44
views
Django filter objects which JSONField value contains in another model's JSONField values LIST of same "key"
I'm not sure if the title of this post made you understand the problem but let me explain:
I have models:
class ItemCategory(models.Model):
name = CharField()
class Item(models.Model):
brand =...
1
vote
1
answer
56
views
FieldError at /chat/search/ Unsupported lookup 'groupchat_name' for CharField or join on the field not permitted
I'm trying to be able to search chat groups by looking up the chatroom name. I'm using Django Q query...
models.py
class ChatGroup(models.Model):
group_name = models.CharField(max_length=128, ...
0
votes
1
answer
66
views
Django test database creation fails: permission denied to create extension vector
poetry run python manage.py test minigames.test.models
response in terminal:
The currently activated Python version 3.12.9 is not supported by the project (^3.13).
Trying to find and use a compatible ...