Chaining multiple filter() in Django, is this a bug?
I always assumed that chaining multiple filter() calls in Django was always the same as collecting them in a single call.#...
View ArticleDjango query hangs on a model with a ManyToManyField to "self", when adding...
I have an Offer model with a self-referential ManyToManyField:class Offer(models.Model): title = models.CharField(max_length=255) priority = models.PositiveIntegerField(default=100, help_text="The...
View ArticleHow can I use prefetch_related in self related model
I have Menu model which has ForeignKey named parent related with itself.If parent is None it means this menu is parent menu if it shows another Menu object it means it is submenu for its...
View ArticleDjango dumpdata to dump all tables without data
I have been using dumpdata in Django for a while. The fact is that dumpdata dumps all of the data including table details. Now, I have a requirement to dump all the tables without even including the...
View ArticleUse Django Subquery as FROM table or CTE in order to have a Window over an...
I am trying to sum costs within groups, and then add a cumulative cost over multiple groups. Simplified:class Cost(Model): year = IntegerField() month = IntegerField() cost = DecimalField()select...
View ArticleAccess django translated fields in values
I have a model with translate fieldsclass Certificate(TranslatableModel, BaseModel): enabled = models.BooleanField(default=True) translations = TranslatedFields(...
View ArticleComplex Django Query Spanning Multiple Tables
Table set up for reference only:class CustomerInformation(Model): first_name = charfield() last_name = charfield()class CustomerCreditInformation(Model): customer = OneToOneField(CustomerInformation,...
View ArticleDjango DB backup and restore
I am using Postgres in my Django project. My concern is regarding database backup and restore.Let's say I have a Django model named TestModel with name as a char field in that TestModel. I have ran...
View ArticleHow to use prefetch_related with Django's DetailView
I want to use prefetch_related with Django's DetailView. Model:class Customer(models.Model): name = models.CharField( verbose_name='customer name', max_length=100 ) # Other fieldsclass...
View Articleget TaskResult object when testing the Celery task in Django
I have a very simple celery task inside my Django application:@app.task(name='test', bind=True)def my_celery_task(self, schema=None, ref_id=None, user_id=None): print('Start Task 1') with...
View Articledjango rest framework, how to prefetch_related with a single object
for some reason,I pass an instance(not queryset) to ModelSerializer. but I want to do prefetch_related with this instance.# instance is a Workout objectinstance = queryset.order_by('?').first()# I want...
View ArticleOptimzing jsonfield filtering values of a certain index
Scenario:qs = mymodal.objects.values('foo__0__json_key').filter(foo__0__json_key__gte=numeric_value)Where we know that "json_key" is a numeric value inside the 0th index of foo.E.g.foo = [{"json_key":...
View ArticleHow to perform addition and subtraction of values from individual cells of a...
This picture is visual example of database table made in excel.How do you make cell G6 the sum of G5 and C6 and then subtract D6 and E6 from it? And that every lower cell of the G7, G8... should have...
View ArticleDjango ArrayField. How to save nested array of time through django admin?
I already asked this question several months ago.Question is stupid, but i cant find solution. What a valid format for saving nested array of time from simple form text field?I have ArrayField like...
View Articleannotation with a table referred to by content_type + object_id in DjangoORM
So issue is I need to filter by title field that in many others tables.class Model uses contenttypes framework in django. It refers to several tables that have a title field (field I want to filter...
View ArticleSlow performance when order by field in foreign key
When a queryset is sorted by a field in a related model performance decreases drastically. I use mysql.For example, I have two models:class Event(models.Model): idEvent =...
View ArticleSelect for update through a foreign key
modelsclass Transaction(models.Model): STATUSES = ( (FAILED_STATUS, "Failed"), (DONE_STATUS, "Done"), (PENDING_STATUS, "Pending"), (BANK_ACCEPTANCE, "Bank Acceptance"), ) amount =...
View Article`UNIQUE constraint failed at: pharmcare_patient.id` in my pharmcare app
I have a Django app in my project I am currently working on called pharmcare, and I kind of getting into a unique constraint issue whenever I want to override the save() method to insert/save the total...
View ArticleHow to find Postgres version from Django?
I want to know version of the default Postgres database. How to find it using Django?
View Articledifferent results with icontains in django ORM
I'm filtering results from django database (mysql) with the following:queryset = MyModel.objects.filter(value_name__icontains=search).order_by("pk")class MyModel(models.Model): ... value_name =...
View Article
More Pages to Explore .....