django

How to implement a paginator that doesn't call count(*)

好久不见. 提交于 2021-02-18 05:11:50
问题 I am working on a django website that has a MySQL innodb backend. We have hundreds of thousands of records in several of our tables and this is causing some site stability/performance issues in the admin. Specifically, django likes to make count(*) queries when creating the paginators, and this is causing lots of problems. With Django 1.3.x, they started to allow for custom pagination classes to be provided. So, I'm interested in finding a way to appropriately speed up or eliminate these

How to implement a paginator that doesn't call count(*)

纵饮孤独 提交于 2021-02-18 05:09:46
问题 I am working on a django website that has a MySQL innodb backend. We have hundreds of thousands of records in several of our tables and this is causing some site stability/performance issues in the admin. Specifically, django likes to make count(*) queries when creating the paginators, and this is causing lots of problems. With Django 1.3.x, they started to allow for custom pagination classes to be provided. So, I'm interested in finding a way to appropriately speed up or eliminate these

What is doing __str__ function in Django?

爷,独闯天下 提交于 2021-02-18 05:05:03
问题 I'm reading and trying to understand django documentation so I have a logical question. There is my models.py file from django.db import models # Create your models here. class Blog(models.Model): name = models.CharField(max_length=255) tagline = models.TextField() def __str__(self): return self.name class Author(models.Model): name = models.CharField(max_length=255) email = models.EmailField() def __str__(self): return self.name class Post(models.Model): blog = models.ForeignKey(Blog)

What is doing __str__ function in Django?

烈酒焚心 提交于 2021-02-18 05:01:06
问题 I'm reading and trying to understand django documentation so I have a logical question. There is my models.py file from django.db import models # Create your models here. class Blog(models.Model): name = models.CharField(max_length=255) tagline = models.TextField() def __str__(self): return self.name class Author(models.Model): name = models.CharField(max_length=255) email = models.EmailField() def __str__(self): return self.name class Post(models.Model): blog = models.ForeignKey(Blog)

Vue框架(四)——路由跳转、路由传参、cookies、axios、跨域问题、element-ui模块

为君一笑 提交于 2021-02-18 02:18:47
路由跳转 三种方式: $router.push / $router.go / router-link to this.$router.push( ' /course ' ); this.$router.push({name: course}); //这个name是router.js里面设置的name this.$router.go( -1 ); //页面后退 this.$router.go( 1 ); //前进 <router-link to= " /course " >课程页</router-link> <router-link :to= " {name: 'course'} " >课程页</router-link> 路由传参 第一种: router.js设置 routes: [ // ... { path: ' /course/:id/detail ' , // :id接收参数 name: ' course-detail ' , component: CourseDetail }, ] 跳转 .vue <template> <router-link :to= " ` /course/${course.id}/detail ` " >{{ course.name }}</router-link> </template> <script> // ... goDetail() {

Python 学习日记 第一天

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-18 01:49:49
日常鸡汤:   当你去想要去放纵自己的时候,多想想你的父母在干什么! 一、Python简介: 都说“Hello,Wolrd”是万恶之起源,但我觉得介绍才是万恶的起源。 Python 创始人龟叔(Guido van Rossum) 1.主要应用的领域: 云计算:OpenStack WEB开发:Django等框架 科学运算、人工智能:典型库NumPy等 系统运维 金融:量化交易,金融分析 图形GUI:PyQT等 2.编译和解释的区别: 编译器 是把源程序的每一条语句都编译成机器语言,并保存成二进制文件,这样运行时计算机可以直接以机器语言来运行此程序,速度很快。 解释器 是在执行程序时,才一条一条的解释解释成机器语言给计算机来执行,所以运算速度慢,跨平台性高 3.Python语言的特点:   “优雅”、“明确”、“简单”   并且Python是一门解释型的弱类型语言 二、第一个Python程序 1 # _*_ encoding:utf-8 _*_ 2 print ( " Hello,Word " ) frist   当python的版本为2系列的时候需要在编辑代码前加上一行 # _*_ encoding:utf-8 _*_   因为Python2系列的版本默认不支持utf-8的编码,python3 系列没有这个问题 三、变量 1.常量:   在python中不存在绝对的常量,只是约定俗称

Django - How to filter by date with Django Rest Framework?

依然范特西╮ 提交于 2021-02-17 21:35:29
问题 I have some model with a timestamp field: models.py class Event(models.Model): event_type = models.CharField( max_length=100, choices=EVENT_TYPE_CHOICES, verbose_name=_("Event Type") ) event_model = models.CharField( max_length=100, choices=EVENT_MODEL_CHOICES, verbose_name=_("Event Model") ) timestamp = models.DateTimeField(auto_now=True, verbose_name=_("Timestamp")) I'm then using Django-rest-framework to create an API endpoint for this class, with django-filter providing a filtering

Django REST Framework: raise error when extra fields are present on POST

寵の児 提交于 2021-02-17 21:13:32
问题 When you're writing a serializer, it is trivial to specify which fields will be included (via Meta 's fields ), setting read/write permissions on them and validating them. However, I was wondering if there is an easy way to specify that only the fields that are included are to be expected and any extra keys passed in should raise an error. E.g. say, I have a serializer class ModelASerializer(serializers.ModelSerializer): class Meta: model = models.ModelA fields = ('name', 'number') Supposed

Django REST Framework: raise error when extra fields are present on POST

流过昼夜 提交于 2021-02-17 21:12:02
问题 When you're writing a serializer, it is trivial to specify which fields will be included (via Meta 's fields ), setting read/write permissions on them and validating them. However, I was wondering if there is an easy way to specify that only the fields that are included are to be expected and any extra keys passed in should raise an error. E.g. say, I have a serializer class ModelASerializer(serializers.ModelSerializer): class Meta: model = models.ModelA fields = ('name', 'number') Supposed

Serve protected media files with django

≡放荡痞女 提交于 2021-02-17 20:55:39
问题 I'd like Django to serve some media files (e.g. user-uploaded files) only for logged-in users. Since my site is quite low-traffic, I think I will keep things simple and do not use django-sendfile to tell Nginx when to serve a file. Instead I'll let Django/Gunicorn do the job. To me this seems a lot simpler and for a low traffic site this maybe more secure. But what is the best way to organize the file storage location? Media files are all stored below MEDIA_ROOT and this directory is served