Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How to JOIN three tables with Django ORM

queryset = Artist.objects.select_related(
    'songs', 'fans'
).filter(songs__title__icontains='love', fans__votes_casted__gte=100)
Comment

How to JOIN three tables with Django ORM

from django.db import models

class Artist(models.Model):
    name = models.CharField(max_length=60)
    year_established = models.SmallIntegerField()
    votes = models.IntegerField(blank=True, null=True)


class Song(models.Model):
    artist = models.ForeignKey(Artist, related_name='songs')
    title = models.CharField(max_length=5)
    votes = models.IntegerField()


class Fan(models.Model):
    artist = models.ForeignKey(Artist, related_name='fans')
    name = models.CharField(max_length=5)
    votes_casted = models.IntegerField()
Comment

PREVIOUS NEXT
Code Example
Python :: stop for loop python 
Python :: how to remove outliers in dataset in python 
Python :: .sort python 
Python :: django orm filter 
Python :: how to change help command on discord python 
Python :: why is c faster than python 
Python :: removing value from list python 
Python :: perfect numbers python 
Python :: bresenham circle drawing algorithm 
Python :: django delete model from database 
Python :: python string after character 
Python :: how to check if two strings are same in python 
Python :: python list pop equivalent 
Python :: cudart64_110.dll not found 
Python :: python try except print error 
Python :: add new element to python dictionary 
Python :: set() python 
Python :: python if in one line 
Python :: python max of two numbers 
Python :: django select_related and prefetch_related 
Python :: recall calculate confusion matrix .ravel() 
Python :: buble short 
Python :: quadrilateral 
Python :: doormat pattern 
Python :: pdf reading shows gibberish python 
Python :: exception: python in worker has different version 3.7 than that in driver 3.8, pyspark cannot run with different minor versions. please check environment variables pyspark_python and pyspark_driver_python are correctly set. 
Python :: pandascheck if two columns match and populate new column 
Python :: Update only values in python 
Python :: how to output varibles in python 
Python :: mengetahui informasi statistik dari suatu dataset secara cepat. 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =