Quantcast
Channel: Active questions tagged django-orm - Stack Overflow
Browsing all 102 articles
Browse latest View live

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 Article



Django 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 Article

How 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 Article

Django 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 Article

Use 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 Article


Access django translated fields in values

I have a model with translate fieldsclass Certificate(TranslatableModel, BaseModel): enabled = models.BooleanField(default=True) translations = TranslatedFields(...

View Article

Complex 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 Article

Django 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 Article


How 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 Article


get 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 Article

Image may be NSFW.
Clik here to view.

django 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 Article

Optimzing 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 Article

Image may be NSFW.
Clik here to view.

How 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 Article


Django 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 Article

annotation 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 Article


Slow 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 Article

Select 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 Article

How to find Postgres version from Django?

I want to know version of the default Postgres database. How to find it using Django?

View Article

different 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
Browsing all 102 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>