Questions tagged [django-select-related]

Django operator, which returns a queryset that follows and caches foreign key relationships, in order to avoid hitting the database in future calls that require use of foreign keys.

147 questions
0
votes
1 answer

Django Get Related with Multiple Models

Hi I'm new in Django and don't know how to get related objects with multiple models. My code: #models.py class Candidate(models.Model): user = models.OneToOneField(User, primary_key=True) birth = models.CharField(max_length=50) …
0
votes
1 answer

Correct use of select_related

I currently have the following code that I want to optimize using select_related. The aim is to find out the set of BaseReward for which there is at least one Voucher with is_active = True class Basereward(models.Model): active =…
0
votes
2 answers

Create an alias of relation in select_related in Django

i have the model: Rubric(models.Model): name = models.CharField(max_length=255) Rubric has seo parameters class RubricSeo(models.Model): rubric = models.OneToOneField(Rubric) title = models.CharField(max_length=255) To select the…
yital9
  • 6,544
  • 15
  • 41
  • 54
0
votes
2 answers

filter prefetch_related and select_related results

I have 3 models models.py class Book(models.Model): name = models.CharField(max_length=255, primary_key=True) ... class BookTranslation(models.Model): book = models.ForeignKey(Book, related_name='translations') language =…
0
votes
1 answer

How to get related set models without hit database in Django

Here you'll always get two separate db calls, and adding select_related() anywhere won't help at all. One extra db call isn't that significant.
    {% for obj in myobjects %}
  • {{ myobj.name }}
    • {% for relobj in…
0
votes
2 answers

Selecting data from few relational tables based on few conditions in Django

I'm using Django 1.6 with Python 2.7 and I have few related models: # keys/models.py class Key(models.Model): user = models.ForeignKey('auth.User') is_valid = models.BooleanField() # entities/models.py class Entity(models.Model): user =…
errata
  • 5,695
  • 10
  • 54
  • 99
0
votes
1 answer

How to select a specific related element in Django?

I have a model called 'Projects'. Projects can be featured. If they are, they will be displayed on the home page (Projects.filter(is_featured=True)) Each project contains several slides. These slides can be featured (Slide.is_featured=True), and…
XelharK
  • 598
  • 8
  • 21
0
votes
1 answer

What's the proper way to optimize this Django code with select_related/prefetch_related?

I have a simple situation with two models and a ForeignKey: class Image(models.Model): # Stuff here def iotd_date(self): iotd = self.image_of_the_day.all() if iotd: return iotd[0].date return None class…
Salvatore Iovene
  • 2,064
  • 1
  • 17
  • 31
0
votes
1 answer

Django: Correct select_related in Class Based View

Hi Stackoverflow people, I am experiencing a strange issue with a select_related query in Django. I have installed the django-cities app, which lists geo information for a large number of cities. In my project model, I have created a foreignkey to…
-1
votes
2 answers

Django tagging select_related

I using Django tagging project. That is was very stable project. Working on django 1.3. But i have a problem. # in models.py from tagging.fields import TagField class Blog(models.Model): title = models.CharField(max_length = 300) …
Ankhaa
  • 1,128
  • 2
  • 12
  • 17
-1
votes
2 answers

Django many-to-many query matching all related fields

I have two models connected by a many-to-many relationship in django. class BuildingMapping(models.Model): name = models.CharField(max_length=1000, null=False) buildings = models.ManyToManyField( Building, related_name="mapping" …
-3
votes
1 answer

INNER JOIN in DJANGO PROJECT (SELECT-RELATED)

I would like to know how run this sql code in django project: > SELECT * FROM COLETA INNER JOIN TRANSDUTOR ON COLETA.id_transdutor = > TRANSDUTOR.id_transdutor INNER JOIN USER ON TRANSDUTOR.id_user = > USER.id_user Note that I have 3 tables…
Yamada
  • 1
  • 1
1 2 3
9
10