models

Django REST framework基础:视图和路由

你。 提交于 2019-12-04 04:55:10
在原来modelserializers基础上进行了一次封装方便了使用# author class AuthorModelSerializers(serializers.ModelSerializer): class Meta: model = models.Author fields = "__all__" from rest_framework import mixins from rest_framework import generics class AuthorView(mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView): # queryset serializer 这两个方法一定要定义成这个不然取不到值 queryset = models.Author.objects.all() serializer_class = AuthorModelSerializers def get(self, request, *args, **kwargs): return self.list(request, *args, **kwargs) def post(self, request, *args, **kwargs): return self.create(request, *args,

tensorflow tfserving 部署多个模型、使用不同版本的模型

只谈情不闲聊 提交于 2019-12-04 03:46:03
本篇主要介绍使用tfserving和docker同时部署多个模型,使用不同版本的模型,基本的流程与部署单个模型的过程类似,(关于运行tfserving容器使用单个模型进行预测的相关步骤可以参见 使用docker和tf serving搭建模型预测服务。 )不同之处在于需要用到一个多模型的配置文件。首先得到多个可以用于tfserving预测的模型文件,相关步骤可以参考 使用savedModel保存模型 。本例中用 使用savedModel保存模型 中的相关代码生成三个模型,分别建立三个文件夹,将得到的模型分别放入,最后的文件结构如下图。其中100001文件夹表示模型的版本,可以在model1下放置不同版本的模型,默认情况下会加载具有较大版本号数字的模型。 1. 多模型部署 在multiModel文件夹下新建一个配置文件 model.config ,文件内容为: model_config_list:{ config:{ name:"model1", base_path:"/models/multiModel/model1", model_platform:"tensorflow" }, config:{ name:"model2", base_path:"/models/multiModel/model2", model_platform:"tensorflow" }, config:{

How to run multiple graphs in a Session - Tensorflow API

♀尐吖头ヾ 提交于 2019-12-04 02:55:51
Tensorflow API has provided few pre-trained models and allowed us to trained them with any dataset. I would like to know how to initialize and use multiple graphs in one tensorflow session. I want to import two trained models in two graphs and utilize them for object detection, but I am lost in trying to run multiple graphs in one session. Is there any particular method to work with multiple graphs in one session?. Another issue is, even if I create two different sessions for 2 different graphs and try to work with them, I end up getting similar result in the second one as of first

django 多对多反序列添加

巧了我就是萌 提交于 2019-12-04 02:34:11
# 添加学生class Addstu1(APIView): def post(self,request): data = request.data data['img'] = '123456' # img直接写成了死的数据 print(data) ss=Stuerializers1(data=data) if ss.is_valid(): ss.save() return Response({'code':200,'message':'添加成功'}) return Response({'code':10020,'message':'添加失败'})最重要的序列化部分 # 多对多添加学生class Stuerializers1(serializers.Serializer): name = serializers.CharField(max_length=32) img = serializers.CharField(max_length=255) cid = serializers.ListField() # ListField 可以添加多个 def create(self,data): cid = data.pop('cid') #cid并不是我stu里的字段 所以弹出cid ss = Stu.objects.create(**data) #添加stu表 ss.duo.set

How to have two models reference each other Django

◇◆丶佛笑我妖孽 提交于 2019-12-03 22:20:24
I have the following code: class Game(models.Model): title = models.CharField(max_length=50) summery = models.CharField(max_length=500) key = models.IntegerField() pin = models.CharField(max_length=12) complete = models.BooleanField() invite_sent = models.DateTimeField() on = models.ForeignKey(Member, blank = True) #<---- class Member(models.Model): email = models.CharField(max_length=100) color = models.CharField(max_length=11) game = models.ForeignKey(Game) #<---- The "on" foreign key links to one of the members (who's turn it is). All members of a game have their "game" foreign key set to

Nested models of the same 'class' in the Backbone.js framework?

情到浓时终转凉″ 提交于 2019-12-03 21:38:40
I'm new to Backbone. Is it possible to define a Model in backbone which contains a list of Models of the same type? Example: MyModel = Backbone.Model.extend({ initialize: function() { nestedMyModels:new Array(); }, addMyModel: function(aModel) { // Code here would push() aModel onto array }, render: function() { // Loop through array calling render() recursively } }); I would then have a View which started a recursive call to render(). Example: MyView = Backbone.View.extend({ render:function() { this.model.render(); } }); 1 no arrays but Collections Always that you think in an Array of Models

django的orm操作优化

≡放荡痞女 提交于 2019-12-03 16:46:40
django的orm操作优化 models.py from django.db import models class Author(models.Model): name = models.CharField(max_length=16) age = models.IntegerField() class Book(models.Model): authors = models.ManyToManyField('Author') pubs = models.ForeignKey("Publish",on_delete=models.CASCADE) title = models.CharField(max_length=32) pubtime = models.DateField() class Publish(models.Model): name = models.CharField(max_length=32) 优化一:尽量不查对象,能用values就是用values 直接使用对象查询的结果是5条sql语句 def youhua(request): # 使用对象查 obj_list = models.Book.objects.all() for obj in obj_list: print(obj.title,obj.pubs.name) return render

How can I make all CharField in uppercase direct in model?

我的未来我决定 提交于 2019-12-03 16:45:28
I tried to use UpperCase in all my CharField, in all my Django Model. Today I have some code in my save method: def save(self, *args, **kwargs): for field_name in ['razao_social', 'nome_fantasia', 'cidade', 'endereco','bairro', 'uf', 'cli_parc_nomeparc', 'cli_repr_nomerepr']: val = getattr(self, field_name, False) if val: setattr(self, field_name, val.upper()) super(Pessoa, self).save(*args, **kwargs) But its take some time. There`s any method to put some uppercase=True in my models? Thanks. The correct way would be to define custom model field: from django.db import models from django.utils

Creating Qt models for tree views

孤人 提交于 2019-12-03 16:36:40
问题 I'm writing an application in Qt (with C++) and I need to represent an object structure in a tree view. One of the ways to do this is to create a model for this, but I'm still quite confused after reading the Qt documentation about the subject. The "structure" I have is pretty simple - there's a Project object that holds Task objects in a std::vector container. These tasks can also hold child tasks. I've already written methods to read & write these projects to/from XML files using Qt's XML

django: How to make one form from multiple models containing foreignkeys

情到浓时终转凉″ 提交于 2019-12-03 16:13:48
I am trying to make a form on one page that uses multiple models. The models reference each other. I am having trouble getting the form to validate because I cant figure out how to get the id of two of the models used in the form into the form to validate it. I used a hidden key in the template but I cant figure out how to make it work in the views My code is below: views: def the_view(request, a_id,): if request.method == 'POST': b_form= BForm(request.POST) c_form =CForm(request.POST) print "post" if b_form.is_valid() and c_form.is_valid(): print "valid" b_form.save() c_form.save() return