标签:ble port query tle sele foreign 吸引力 等于 cas
from django.db import models
class Category(models.Model):
name = models.CharField(max_length=100)
class Meta:
db_table = 'category'
class Article(models.Model):
title = models.CharField(max_length=100)
content = models.TextField()
category = models.ForeignKey('Category', on_delete=models.CASCADE, null=True)
def __str__(self):
return "<(Article: id: %s,title: %s, content: %s)>" % (self.id, self.title, self.content)
class Meta:
db_table = 'article'
from .models import Article, Category
from django.http import HttpResponse
def index(request):
# gte:查找出文章id大于等于3的文章
articles = Article.objects.filter(id__gte=3)
print(articles)
print(articles.query)
return HttpResponse("success")
<QuerySet [<Article: <(Article: id: 3,title: 钢铁是怎样炼成的, content: 你好)>>,
<Article: <(Article: id: 4,title: 中国吸引力, content: 精彩极了)>>]>
原生sql语句为:SELECT article
.id
, article
.title
, article
.content
, article
.category_id
FROM article
WHERE article
.id
>= 3
from .models import Article, Category
from django.http import HttpResponse
def index(request):
articles = Article.objects.filter(id__gt=3)
print(articles)
print(articles.query)
return HttpResponse("success")
<QuerySet [<Article: <(Article: id: 4,title: 中国吸引力, content: 精彩极了
)>>]>
原生sql语句:SELECT article
.id
, article
.title
, article
.content
, article
.category_id
FROM article
WHERE article
.id
> 3
from .models import Article, Category
from django.http import HttpResponse
def index(request):
articles = Article.objects.filter(id__lte=3)
print(articles)
print(articles.query)
return HttpResponse("success")
<QuerySet [<Article: <(Article: id: 1,title: Hello, content: 你好)>>,
<Article: <(Article: id: 2,title: Hello World, content: 大家好)>>,
<Article: <(Article: id: 3,title: 钢铁是怎样炼成的, content: 你好)>>]>
SELECT article
.id
, article
.title
, article
.content
, article
.category_id
FROM article
WHERE article
.id
<= 3
from .models import Article, Category
from django.http import HttpResponse
def index(request):
articles = Article.objects.filter(id__lt=3)
print(articles)
print(articles.query)
return HttpResponse("success")
<QuerySet [<Article: <(Article: id: 1,title: Hello, content: 你好)>>, <Article: <(Article: id: 2,title: Hello World, content: 大家好)>>]>
SELECT article
.id
, article
.title
, article
.content
, article
.category_id
FROM article
WHERE article
.id
< 3
标签:ble port query tle sele foreign 吸引力 等于 cas
原文地址:https://www.cnblogs.com/guyan-2020/p/12262494.html