django-select-related Questions

3

Solved

I update project from Django 1.6.7 to 1.8.7 and I have got following exception with Django 1.8, although with Django 1.6 it code was right: In[2]: from apps.route import models In[3]: models.Trace....

6

Solved

In Django doc: select_related() "follows" foreign-key relationships, selecting additional related-object data when it executes its query. prefetch_related() does a separate lookup for ea...

1

Solved

I have a strange situation. I've done so much reading on avoiding the N+1 problem and have tried prefetching but to no avail. My setup is like this: Models: class A(models.Model): somefield1 = mod...
Burmeister asked 30/9, 2022 at 21:37

4

How does select_related work with a model which has multiple foreign keys? Does it just choose the first one? class Model: fkey1, fkey2, fkey3... The documentation doesn't say anything about this, ...
Illtimed asked 17/1, 2013 at 18:12

3

Solved

I'm trying to figure out how to use select_related or prefetch_related to optimize a query from the other end of a foreign key. For example: Say I have some models such as the following: class ...

0

I am trying to build an endpoint for the default django's Group model, which has name and permissions fields:- Here are my view and serializers:- Serializers.py:- class GroupSerializer(serializers....

3

Solved

I would like to be able to check if a related object has already been fetched by using either select_related or prefetch_related, so that I can serialize the data accordingly. Here is an example: ...
Debar asked 4/4, 2016 at 12:3

1

Solved

I have seem some examples of how to prefetch_related fields in a forward and backward relationship in Django, but I have doubts about how can this be applied if we want to prefetch all the fields o...
Keelby asked 27/5, 2021 at 9:24

3

Solved

I have two models Article and Blog related using a foreign key. I want to select only blog name while extracting the article. articles = Articles.objects.all().select_related('blog__name') The q...

3

Solved

I've got an app where users create pages. I want to run a simple DB query that returns how many users have created more than 2 pages. This is essentially what I want to do, but of course it's not ...
Fable asked 29/6, 2011 at 18:57

1

Solved

I have two models from different apps: class Measure(models.Model): date = models.DateTimeField(default="2018-01-23 15:55") average = models.FloatField(default=0) class Sensor(models.Model): m...

2

Solved

I read the documentation and all the related questions here but I haven't properly understood how select_related behaves on chained/multiple foreign keys. Assume we have the following models: cl...
Krieg asked 19/9, 2018 at 16:13

4

Solved

I have the following models: class User(models.Model): name = models.Charfield() email = models.EmailField() class Friendship(models.Model): from_friend = models.ForeignKey(User) to_friend ...

1

Solved

I would like to prefetch a model property to a queryset in Django. Is there a way do that ? Here are the three models: class Place(models.Model): name = models.CharField(max_length=200, blank=Tr...
Aerograph asked 17/12, 2017 at 11:28

1

Solved

I have created a OneToOneField(parent) in Child model with related_name='children'. In my views, I used select_related to get the queryset. But in my page the list of children associated to a paren...

1

Solved

I created this simple set of data to illustrate my point. It is a simple model with no further relations to any other model. I need to group the data above by topicid, find the max date for each...
Tea asked 19/6, 2016 at 14:3

3

Solved

Imagine the following model: class Parent(Model): ... class Child(Model) father = ForeignKey(Parent) ... Some parents have children, others do not (they're not parents in the real meaning, i...
Osseous asked 4/6, 2010 at 15:29

1

Solved

I have a User model and UserProfile model. In the User model I'd like to order my query so that its in alphabetical order by last_name. Then I'd like to order it by the User_profiles "title" attrib...
Wigwam asked 7/5, 2012 at 19:47

3

Solved

Should entry_set be cached with select_related? My DB is still getting calls even after I use select_related. The pertinent sections class Alias(models.Model): achievements = models.ManyToManyFi...
Conium asked 29/6, 2009 at 6:34

2

Solved

I have : class Award(models.Model) : name = models.CharField(max_length=100, db_index=True) class Alias(models.Model) : awards = models.ManyToManyField('Award', through='Achiever') class Achie...
Raddle asked 6/9, 2009 at 23:52

2

Solved

I'm getting thousands of these queries when I try to open up a model in the Django admin interface and it's leading to a serious performance issue. [sql] SELECT ... FROM `auth_user` WHERE `auth_us...
Shifflett asked 15/3, 2012 at 12:26

1

Solved

Is there any way of using get_object_or_404 and select_related together or any other way to achieve the result of using these two together(except from putting it in try/except)??
Cunningham asked 8/7, 2011 at 12:38

1

Solved

In my Django app I want to use select_related() on a QuerySet to "follow" a ForeignKey field, but I only need to access a few of the fields on the "followed" model instance. Can I use the defer() m...
Heavyfooted asked 7/5, 2011 at 4:2

1

I have a simple music schema: Artist, Release, Track, and Song. The first 3 are all logical constructs while the fourth (Song) is a specific instance of an (Artist, Release, Track) as an mp3, wav, ...
Deerdre asked 23/10, 2009 at 7:37
1

© 2022 - 2024 — McMap. All rights reserved.