django-orm Questions
3
Solved
Consider the following:
status = queryset.values('status').annotate(count=Count('status'))
where status field is a CharField with choices. This will result in a list of dictionaries with status ...
Sphinx asked 31/7, 2014 at 13:49
5
Solved
I want my application to have default data such as user types.
What's the most efficient way to manage default data after migrations?
It needs to handle situations such as, after I add a new table,...
Johannajohannah asked 28/9, 2016 at 6:21
2
I want to count amount of Users for same Product
models.py
class Product(models.Model):
pass
class User(models.Model):
product = models.ForeignKey(Product)
age = models.IntegerField(blank=True...
Isherwood asked 13/6, 2019 at 5:0
4
Solved
I'm looping through a list of objects and saving. I need the newly generated id or pointer id right after the save but it is None.
Here is my code:
for category in category_list:
saved_categor...
Valeda asked 30/11, 2013 at 19:16
2
Is it possible to print the SQL made by an queryset.exists() statement in Django?
Heterotopia asked 6/2, 2015 at 23:1
5
Solved
I'm trying to optimize my ORM queries in django. I use connection.queries to view the queries that django generate for me.
Assuming I have these models:
class Book(models.Model):
name = models.C...
Apoplectic asked 20/10, 2015 at 7:29
5
Solved
I have a model something like this:
class Task(models.Model):
progress = models.PositiveIntegerField()
estimated_days = models.PositiveIntegerField()
Now I would like to do a calculation Sum(p...
Aleedis asked 28/8, 2012 at 18:54
5
Solved
I have a very simple query: select * from tbl1 where title not in('asdasd', 'asdasd').
How do I translate that to Django? It's like I want the opposite of: Table.objects.filter(title__in=myListOf...
Extrasystole asked 25/1, 2012 at 13:29
1
Problem
Hello,
I'm using Graphene Django and Graphene Relay with Python 3.7. I'm trying to make a custom filter for the requests in GraphQL using Django filters.
My table looks like this:
| id(...
Diageotropism asked 14/8, 2019 at 15:46
3
In Django it's common to do the following
MyModel.objects.filter(id__in=[huge array])
However it's not very efficient as described in the following answer here: https://dba.stackexchange.com/que...
Binder asked 24/10, 2018 at 17:7
2
Solved
I have for example a model like this:
class Transaction(models.Model):
amount = models.FloatField()
seller = models.ForeignKey(User, related_name='sells', on_delete=models.CASCADE)
buyer = mode...
Vela asked 4/1, 2019 at 10:57
4
Solved
Is it possible to replicate this kind of specific sql ordering in the django ORM:
order by
(case
when id = 5 then 1
when id = 2 then 2
when id = 3 then 3
when id = 1 then 4
when id = 4 ...
Edge asked 26/4, 2012 at 8:35
2
Solved
My basic problem statement is that I want to fetch every row but in chunks only 2000 rows at one time from a table having 1 million rows. And after these chunked queries are evaluated i want to del...
Sabadell asked 18/3, 2020 at 9:45
7
Solved
What is the equivalent of the following SQL statement in Django?
SELECT * FROM table_name WHERE string LIKE pattern;
I tried this:
result = table.objects.filter( pattern in string )
but it didn't...
Vhf asked 9/8, 2013 at 6:0
5
Solved
I am trying to update and modify a string field Django's ORM. The equivalent SQL to do this is:
UPDATE example_table SET string_field = REPLACE(string_field, 'old text', 'new text');
With that q...
Aleedis asked 30/1, 2014 at 18:42
4
Solved
I would like to sort my result after I have grabbed unique results based on two fields. The problem I'm having is that I cannot use two order_by in Django. Django clears the previous order_by() whe...
Rumery asked 17/1, 2017 at 15:12
6
Solved
I'm experiencing a weird problem which I hope someone in here may be able to shed some light on.
I'm overriding the save() method of a model to add some values to a ManyToMany-field after running ...
Persephone asked 1/6, 2011 at 11:12
2
I'm trying to do an inner join on these 3 tables using PersonScore but it can't find persontype. What am i doing wrong?
models:
class PersonScore(models.Model):
id = models.IntegerField(primary_...
Placative asked 4/8, 2017 at 18:24
5
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 parent(ma...
An asked 26/2, 2018 at 15:30
5
Solved
I am new to Django and didn't find any reference regarding this issue. I am getting this error when i use many to many field in Django model (models.py). I guess the issue is assigning m2m field in...
Washburn asked 25/4, 2018 at 6:15
18
Solved
How does one convert a django Model object to a dict with all of its fields? All ideally includes foreign keys and fields with editable=False.
Let me elaborate. Let's say I have a django model like...
Rollick asked 21/2, 2014 at 5:2
3
Solved
Jump to edit to see more real-life code example, that doesn't work after changing the query order
Here are my models:
class ModelA(models.Model):
field_1a = models.CharField(max_length=32)
fiel...
Betaine asked 6/3, 2020 at 11:2
4
Solved
I have a list of names, e.g.:
name_list = ['Alpha', 'bEtA', 'omegA']
Currently I have the following queryset:
MyModel.objects.filter(name__in=name_list)
I would like to be able to filter the ...
Hippocras asked 16/2, 2013 at 6:7
3
I'm making a QA site that is similar to the page you're on right now. I'm attempting to order answers by their score, but answers which have no votes are having their score set to None rather than ...
Outsole asked 28/5, 2011 at 9:1
6
Solved
I want to write a Django query equivalent to this SQL query:
SELECT * from user where income >= 5000 or income is NULL.
How to construct the Django queryset filter?
User.objects.filter(incom...
Scissel asked 4/7, 2011 at 6:4
1 Next >
© 2022 - 2024 — McMap. All rights reserved.