我试图按创建日期过滤对象并按季度对其进行排序。
我有一个这样的样本模型
psycopg2.OperationalError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
然后我有另一个以这种方式与Assets模型关联的模型,
db = pg.connect(
dbname=config.db_name,
user=config.db_user,
password=config.db_password,
host=config.db_host,
port=config.db_port
)
with db.cursor() as c:
c.execute("""
CREATE EXTENSION IF NOT EXISTS postgres_fdw;
CREATE SERVER fdw FOREIGN DATA WRAPPER postgres_fdw OPTIONS (...);
CREATE USER MAPPING FOR CURRENT_USER SERVER fdw OPTIONS (...);
CREATE SCHEMA foreign;
IMPORT FOREIGN SCHEMA foreign_schema FROM SERVER fdw INTO foreign;
""")
c.execute("""
CREATE MATERIALIZED VIEW IF NOT EXISTS my_view AS (
SELECT (...)
FROM foreign.foreign_table
);
""")
我收到此错误
class Asset(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
我遵循了此处的示例,并查找了类似的问题,但没有一个解决我的问题 https://docs.djangoproject.com/en/2.2/ref/models/querysets/#quarter
答案 0 :(得分:2)
您使用Django 1.11
,但quarter
仅在2.0中出现:
https://docs.djangoproject.com/en/2.2/releases/2.0/#models
因此,至少要使用Django v2.0
quarter
答案 1 :(得分:1)
它不是与quarter
一起出现,而是与您尝试执行的联接一起出现。
def assets_total_quarterly(self):
q1= self.objects.filter(assets__created_at__quarter=1)
return q1