models

Django-Models与ORM

我们两清 提交于 2020-02-11 08:02:01
一、增加 from django.db import models class Publisher(models.Model): name = models.CharField(max_length=30, verbose_name="名称") address = models.CharField("地址", max_length=50) city = models.CharField('城市',max_length=60) state_province = models.CharField(max_length=30) country = models.CharField(max_length=50) website = models.URLField() class Meta: verbose_name = '出版商' verbose_name_plural = verbose_name def __str__(self): return self.name class Author(models.Model): name = models.CharField(max_length=30) def __str__(self): return self.name class AuthorDetail(models.Model): sex = models.BooleanField

django避免写models.py办法

Deadly 提交于 2020-02-07 04:22:09
用datagrip想建立表格,datagrip中submit以后 在项目目录下执行此命令 python manage.py inspectdb > fenye/models.py(前提是已经正确连接数据库) 其中: fenye是app的名字 来源: CSDN 作者: 东方朔盗仙桃 链接: https://blog.csdn.net/appleyuchi/article/details/104196595

75.ORM聚合函数详解:Sum

依然范特西╮ 提交于 2020-02-04 12:37:33
Sum:某个字段的总和。 1. 求图书的销售总额,示例代码如下: from django . http import HttpResponse from django . db import connections from . models import BookOrder , Book from django . db . models import Sum def index ( request ) : # 1.求图书的销售总额 sum = BookOrder . objects . aggregate ( sum = Sum ( 'price' ) ) print ( sum ) # {'sum': 622.0} print ( connection . queries ) # [{'sql': 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED', 'time': '0.000'}, # {'sql': 'SELECT SUM(`book_order`.`price`) AS `sum` FROM `book_order`', 'time': '0.000'}] return HttpResponse ( "success !" ) 其中,models.py文件中的模型定义为: from django . db

django admin删除记录的同时删除文件

醉酒当歌 提交于 2020-01-30 15:48:50
参考简书文章 Python Django 调用post_delete() 做自定义删除 import os from django . db import models from django . db . models . signals import post_delete from django . dispatch import receiver from django . conf import settings . . . class Media_blog ( models . Model ) : title = models . CharField ( max_length = 50 ) pub_date = models . DateField ( ) content = models . TextField ( ) source = models . CharField ( max_length = 300 ) source_description = models . CharField ( max_length = 50 , null = True , blank = True ) photo = models . ImageField ( null = True , blank = True , upload_to = 'image' , max

stanford-postagger中文词性标注

六月ゝ 毕业季﹏ 提交于 2020-01-28 03:44:40
安装 系统需要安装Java1.6+ http://nlp.stanford.edu/software/tagger.shtml 下载 Download full Stanford Tagger version 3.3.1 [155 MB] 使用说明 标注器有三个模式:标注、训练、测试 这里我们用已经训练好的标注模型, 对于中文有两个(model目录下) chinese-distsim.tagger(性能比较好) chinese-nodistsim.tagger 二者区别 使用 java -mx300m -classpath stanford-postagger.jar edu.stanford.nlp.tagger.maxent.MaxentTagger -model models/chinese-distsim.tagger -textFile inputFile > outputFile java -mx300m -classpath stanford-postagger.jar edu.stanford.nlp.tagger.maxent.MaxentTagger -model models/chinese-nodistsim.tagger -textFile inputFile > outputFile    案例 输入文件:del 今天 天气 相当 不错. 今天 是 个

The State of Transfer Learning in NLP [18 AUGUST 2019]

我怕爱的太早我们不能终老 提交于 2020-01-28 00:18:23
This post expands on the NAACL 2019 tutorial on Transfer Learning in NLP . The tutorial was organized by Matthew Peters, Swabha Swayamdipta, Thomas Wolf, and me. In this post, I highlight key insights and takeaways and provide updates based on recent work. You can see the structure of this post below: The slides , a Colaboratory notebook , and code of the tutorial are available online. Introduction For an overview of what transfer learning is, have a look at this blog post . Our go-to definition throughout this post will be the following, which is illustrated in the diagram below: Transfer

软件工程--四则运算表达式(3)

六月ゝ 毕业季﹏ 提交于 2020-01-27 03:28:32
四则运算题目生成器 这篇文章详细讲述了第三阶段的需求分析、概要设计详细设计和编码阶段的工作 如果对上一阶段实现的功能感兴趣,请移步 软件工程–四则表达式(2) 如果对可行性分析和问题定义、PSP表格感兴趣,请移步 软件工程–四则运算表达式 第三阶段:网站部分 概述 剩下的主要是所搭网站的前端后端部分 所使用的架构是Django架构,同样是python写的开源服务器架构 Django版本2.27 没有使用最新的3.0版本因为3.0版本当中据说有未修复的bug 对于先前已经实现的功能,引入只需要将源码打包在一个文件夹里,就可以在后端轻松引入 网站的MVC模型 这个项目是严格遵循MVC设计模式实现的,所以在此介绍一下Django中的MVC模型 Model模型 Django中的模型是在每一个app中的models构成的,通过在models中建立class就相当于在数据库中建立了一张表,这些表由Django维护,对于这些表的调用一般是在Views中进行 View视图 Django中的视图是每一个app中的views文件中的函数,view和model的引用是通过import models中的class实现的,通过这种方法可以轻松的实现对数据的增删改查 Controller控制器 Django的控制器是用的urls文件,通过对urls.py的配置将用户请求映射到处理函数,urls

The year in AI: 2019 ML/AI advances recap

回眸只為那壹抹淺笑 提交于 2020-01-26 12:32:42
The year in AI: 2019 ML/AI advances recap 2020-01-26 11:47:14 Source: https://medium.com/@xamat/the-year-in-ai-2019-ml-ai-advances-recap-c6cc1d902d5 It has become somewhat of a tradition for me to do an end-of-year retrospective of advances in AI/ML (see last year’s round up for example), so here we go again! This year started with a big recognition to the impact of Deep Learning when Hinton, Bengio, and Lecun were awarded the Turing award . You might think that after a few years of neck-breaking speed in innovation, this kind of recognition might be signaling that we are getting near some

Problem with asp.net mvc modelBinding behavior

被刻印的时光 ゝ 提交于 2020-01-25 18:50:03
问题 I have a complex form It allows the user to create an IncomeDeclaration which has many Activities. This works fine when the markup for the Activities is like this: <tr> <td>SomeActivity <input type="hidden" value="13123" name="EconomicActivityIncomeDeclarations[0].EconomicActivityId" id="EconomicActivityIncomeDeclarations_0__EconomicActivityId"> </td> <td> <input type="text" name="EconomicActivityIncomeDeclarations[0].GrossIncome" id="EconomicActivityIncomeDeclarations_0__GrossIncome" /> </td

How to store functions in django models

半腔热情 提交于 2020-01-23 13:24:30
问题 edit: I completely rewrote the question as the original one didn't clearly explain my question I want to run a function which is specific to each particular model instance. Ideally I want something like this: class MyModel(models.Model): data = models.CharField(max_length=100) perform_unique_action = models.FunctionField() #stores a function specific to this instance x = MyModel(data='originalx', perform_unique_action=func_for_x) x.perform_unique_action() #will do whatever is specified for