私信  •  关注

Sergey Pugach

Sergey Pugach 最近创建的主题
Sergey Pugach 最近回复了
4 年前
回复了 Sergey Pugach 创建的主题 » 返回带有序列化程序Django REST Framework列表的响应

当你使用 SerializerMethodField 返回序列化程序实例,但不是 data

例如:

contenido_multimedia = serializers.SerializerMethodField()


def get_contenido_multimedia(self, obj):
        contenido = ContenidoMultimedia.objects.filter(producto=obj.pk).order_by('orden_en_producto')
        return MultimediaSerializer(contenido, many=True).data  # <-- here try to add .data

一切都应该改变 序列化方法字段 方法。

5 年前
回复了 Sergey Pugach 创建的主题 » Django 1.11.20获取每个ISO周和年的行数

你可以用 TruncWeek TruncYear :

from django.db.models.functions import TruncWeek, TruncYear

count_for_week = myModel.objects.annotate(
    week=TruncWeek('created_at'),
).values(
    'week',
).annotate(
    count=Count('id'),
)

count_for_year = myModel.objects.annotate(
    year=TruncYear('created_at'),
).values(
    'year',
).annotate(
    count=Count('id'),
)

因此,您将拥有:

 <QuerySet [{'week': datetime.datetime(2019, 2, 18, 0, 0, tzinfo=<UTC>), 'count': 1}]>

在哪里? week year 值将是该范围的开始日期时间:一年中的一周

你可以在Django文档中阅读更多细节 here .

在尝试创建时,似乎没有将用户传递给Post,但user是必需字段。 您可以覆盖 form_valid 方法。

class CreatePostView(CreateView):
    model = Article
    template_name = 'blog/addpost.html'
    fields = ('title', 'text')

    def form_valid(self, form):
        form.instance.user= self.request.user
        return super(CreatePostView, self).form_valid(form)
5 年前
回复了 Sergey Pugach 创建的主题 » 带有postman的django rest框架令牌身份验证

在使用apache时,您需要:

WSGIPassAuthorization On

添加到您的 httpd.conf

更多细节 there .

5 年前
回复了 Sergey Pugach 创建的主题 » 如何找到使用django服务器与android设备联系的本地主机?

您可以使用其中的一些服务,为您的本地主机提供一个隧道,甚至提供一个外部可用的URL。 https .

所以如果你有 http://127.0.0.1:8000/my_endpoint 它将作为 https://{provided_url}/my_enpoint 从互联网上。

5 年前
回复了 Sergey Pugach 创建的主题 » Django测试数据库用户名

发生此错误的原因是,当Gitlab CI运行测试时,它会根据YML文件中设置的设置创建数据库:

variables:
  POSTGRES_DB: asdproject
  POSTGRES_USER: runner
  POSTGRES_PASSWORD: asdpassword

所以 runner 角色和 asdproject 数据库已创建。 但是你把你的数据库url设置为 DATABASE_URL=postgres://postgres:@postgres:5432/asdproject 在哪里? postgres 设置用户。

请尝试 DATABASE_URL=postgres://runner:asdpassword@postgres:5432/asdproject

5 年前
回复了 Sergey Pugach 创建的主题 » 在DigitalOcean中部署Django应用程序后,我看不到服务器中的更改?

为了重新加载django应用程序,请重新启动 gunicorn 服务。

sudo systemctl restart gunicorn