Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django model query join

Blog.objects.filter(entry__headline__contains='Lennon').filter(entry__pub_date__year=2008)
Comment

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

join tables in django orm

class EventsMeetinglocation(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=100)
    address = models.CharField(max_length=200)

    class Meta:
        managed = True
        db_table = 'events_meetinglocation'

class EventsBoardmeeting(models.Model):
    id = models.IntegerField(primary_key=True)
    date = models.DateTimeField()
    agenda_id = models.IntegerField(blank=True, null=True)
    location_id = models.ForeignKey(EventsMeetinglocation)
    minutes_id = models.IntegerField(blank=True, null=True)

    class Meta:
       managed = True
       db_table = 'events_boardmeeting'
Comment

join tables in django orm

def meetings(request):
    meetingData = EventsBoardmeeting.objects.all()
    return render(request, 'board/meetings.html', {'data': meetingData })
Comment

join tables in django orm

{% for x in data %}
   {{ x.location_id.name }}
{% endfor %}
Comment

PREVIOUS NEXT
Code Example
Python :: cudart64_110.dll not found 
Python :: python string and integer concatenation 
Python :: floor function in python 
Python :: docker hub python 
Python :: Send Axios With Post 
Python :: add column to dataframe pandas 
Python :: pk django 
Python :: python search list 
Python :: python get file size 
Python :: python variable type 
Python :: import from parent module package python 
Python :: python dict 
Python :: setup vs code for python 
Python :: get row count dataframe pandas 
Python :: conda 
Python :: Python - How To Pad String With Spaces 
Python :: transcript with timestamps in python 
Python :: convert from R to python 
Python :: reverse sublist of linklist 
Python :: for x in range(1, 10, 3): print(x) 
Python :: b-spline quantile regression with statsmodels 
Python :: initials of name 
Python :: python check if division has remainder 
Python :: #Function in python without input method with multiple results: 
Python :: for loop with 2 variables python 
Python :: pyqt curves exemple 
Python :: concatenate the next row to the previous row pandas 
Python :: pandas split coordinate tuple 
Python :: Another example: using a colorbar to show bar height 
Python :: unpad zeros from string python 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =