models

Django: Advice on designing a model with varying fields

拟墨画扇 提交于 2019-12-08 03:55:32
I'm looking for some advice/opinions on the best way to approach creating a sort-of-dynamic model in django. The structure needs to describe data for Products. There are about 60 different possible data points that could be relevant, with each Product choosing about 20 of those points (with much overlapping) depending on its ProductType. There are about 2 dozen different ProductTypes, with each ProductType falling into one of 6 categories. The obvious, but ungraceful method, would be to just put all 100 data points into the Product model, and just pick and choose, and ignore any fields left

How to build complex django query as a string

穿精又带淫゛_ 提交于 2019-12-08 00:05:11
问题 I am dynamically generating a query string with multiple parameters. I am trying to include the object names ('nut', 'jam') in my string. The query has to be an "OR" query. My code is below and I get the error shown below. The solutions here, here, and here did not work for me. from viewer.models import Model1 from django.db.models import Q list1 = [ {'nut' : 'peanut', 'jam' : 'blueberry'}, {'nut' : 'almond', 'jam' : 'strawberry'} ] query_string = "" for x in list1: if len(query_string) == 0:

Django: Filter objects by date range

时间秒杀一切 提交于 2019-12-07 18:40:16
问题 My object model is : class Event(models.Model): start = models.DateTimeField() end = models.DateTimeField() I need to filter all objects for today. I have one object with start date 2014/03/01 00:00 and end date 2014/10/01 00:00. I need to have this object when filtering objects by today date ex.: Event.objects.filter(start__gte=today, end__lte=today) How can I filter objects by today date and get all results where start > today < end ? 回答1: Get the today's date from datetime.date.today() and

Sharing Models between two Rails Projects - using git submodules?

末鹿安然 提交于 2019-12-07 15:36:10
问题 I have a Rails website which has been divided into two separate projects - the public site, and the administration site. As both sites are using the same database the models are shared between the applications (actually right now they are duplicated). The problem I have here is that when an update to the models occurs in the public project I need to copy the changes over into the admin project. I've had a look around SO and noticed that there was a question which had answers suggesting using

Patterns for mapping data between domain models

限于喜欢 提交于 2019-12-07 13:58:04
问题 This is a common thing that I have been needing to do recently and I was looking for any common patterns to make this a little easier. The main gist of it all is that I have some data models, which are modelled to satisfy the ORM and purely do CRUD operations to objects. These models are currently exposed via repositories/factories (dependant upon if its C or RUD). I then have a view model, which is a bit more readable, and is sprinkled with UI concerns, such as validation and mapping data

Haystack whoosh models() not narrowing models

独自空忆成欢 提交于 2019-12-07 11:35:01
问题 I have the following query locations = SearchQuerySet().filter_or(content__in=words).models(Location) but it's returning other models as well, I would only want to see Location instances. Using Haystack 2.1.0 and whoosh 2.5 Any ideas? 回答1: My current work around is to use filter(django_ct='app_name.model') 回答2: I ran into the same issue with Model filtering being ignored. I was able to get .models() working by downgrading to Haystack 2.0.0 and Whoosh 2.4.1 回答3: This is based partly on James

App Engine query in admin datastore viewer returning different results than programmatic query

六月ゝ 毕业季﹏ 提交于 2019-12-07 08:52:26
问题 I'm flummoxed. I noticed today that some data I thought should be present in my production appengine app wasn't showing up. I connected to the app via the remote console and ran the queries manually. Sure enough it looked like I only had 15 of the 101 rows I was expecting to see. Then I went to my admin console at appengine.google.com and fired up the datastore viewer with the following query: SELECT * FROM Assignment where game = KEY('Game', '201212-foo') and player = KEY('Player', 'player

RESTful API开发规范

女生的网名这么多〃 提交于 2019-12-07 06:41:13
API规范 REST API规范 基本规则 除特殊说明外,Web API遵循如下基本原则: l BIM工作平台以RESTful Web Service的形式提供API。 l 基于安全性考虑,BIM工作平台API需要使用SSL加密传输协议(HTTPS)进行访问。 l BIM工作平台使用 OAuth 2.0协议 进行API访问授权控制。 l 业务系统在访问BIM工作平台API前,需要获得BIM工作平台颁发的应用密钥(APP_KEY和APP_SECRET),并赋予相应的API授权范围。 请求方法 BIM工作平台Web API使用GET、POST、PUT、DELETE等4个标准HTTP请求方法,用于对资源进行访问、创建、修改和删除等标准操作。 l GET:幂等操作,通常用于表达“获取”、“查询”等语义。典型使用场景包括:获取特定资源信息;根据指定条件查询资源信息。 l POST:非幂等操作,通常用于执行“新建”、“创建”等语义。典型使用场景包括:创建一个或多个新的资源; 执行需要大量数据输入的查询;执行不安全或非幂等操作,但其他HTTP方法看上去不适合时。 l PUT:幂等操作,通常用于执行“修改”、“更新”等语义。典型使用场景包括: 更新一个或多个资源;在应用能够决定资源URL的情况下,创建一个资源。 l DELETE:幂等操作,通常用于执行“删除”语义。典型使用场景包括

Zend: How to use a custom function from a view helper in the controller?

℡╲_俬逩灬. 提交于 2019-12-07 05:28:23
问题 Ive got a view helper in library/my/view/helper/gravatar and so in any view I can call $this->gravatar($email) . But how can I access this function in the models (or controllers)? Sorry if its already been asked but Im new and the documentation is bloody awful in parts. Thanks everyone 回答1: In your controller, you can access ViewHelpers through $this->view->gravatar($email) Your model should not call methods from the View, as it would tie the model to the presentation layer. The View may know

How to render a Partial from a Model in Rails 2.3.5

[亡魂溺海] 提交于 2019-12-07 05:27:03
问题 I have a Rails 2.3.5 application and Im trying to render several Partials from within a Model (i know, i know -- im not supposed to). The reason im doing this is im integrating a Comet server (APE) into my Rails app and need to push updates out based on the Model's events (ex. after_create). I have tried doing this: ActionView::Base.new(Rails::Configuration.new.view_path).render(:partial => "pages/show", :locals => {:page => self}) Which allows me to render simple partials that don't user