Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

fetching data from multiple tables using related name in django

class Student(models.Model):
    sid = models.BigIntegerField(primary_key=True)
    nm = models.CharField(max_length=20, blank=True, null=True)
    subject = models.ForeignKey("Subject", related_name="student", blank=True, null=True)

class Subject(models.Model):
    sub = models.CharField(max_length=30, blank=True, null=True)
Comment

fetching data from multiple tables using related name in django

from App.models import Student, Subject
def myFunc():
    students = Student.objects.all()
    for student in students:
        subj = student.subject.sub

def myFunc2():
    subjects = Subject.objects.all()
    for subject in subjects:
        student_name = subject.student.nm
Comment

fetching data from multiple tables using related name in django

Order.objects.select_related('account_customer').all() 
    .values('customer_id', 'other_field_1', ...) 
    .annotate(total_sales=Sum('total_price')) 
    .filter(created_at__year=today.year, created_at__month=today.month)
Comment

PREVIOUS NEXT
Code Example
Python :: how to get data from multiple tables in django 
Python :: remove cog in discord.py 
Python :: how to add an symbol to a certain part of a list python 
Python :: Saving a copy of rcParams settings. 
Python :: store array to nii file 
Python :: pandas query return column 
Python :: "opencv write video" 
Python :: python calculate area diameter circumference circle 
Python :: convert a python object like dict, list, etc to a json object 
Python :: get first element of each group 
Python :: Group by date (day, month, year) 
Python :: # find the n smallest and greatest numbers in list 
Python :: # filter a list 
Python :: Linear Search Python with enumerate 
Python :: number of libraries in python 
Python :: restrict memory use python code 
Python :: pydantic array of objects 
Python :: Code Example of Comparing None with empty string 
Python :: Example of Python Strings with indexing 
Python :: unique character 01 
Python :: python combine images horizontally next to each other 
Python :: python create empty list with size 10 
Python :: dataframe ggplot rownames order 
Python :: Python NumPy broadcast_arrays() Function Syntax 
Python :: how to change the color of console output in python to green 
Python :: Python NumPy asfortranarray Function Tuple to an array 
Python :: making dividers in tkinter 
Python :: retinaface detection 
Python :: NumPy bitwise_and Example When inputs are Boolean 
Python :: NumPy right_shift Code When inputs and bit shift are an arrays 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =