models

从数据库反向生成django项目中的models文件

佐手、 提交于 2019-12-03 15:42:27
1.创建一个django项目 2.在项目配置文件settings.py中配置好数据库的相关配置 3.确保所关联的数据库中已经有表存在 4.在pycharm终端进入到项目的根目录,执行python manage.py inspectdb,查看可以导入到models的相关信息 5.执行python manage.py inspectdb > (需要导入表的app)/models.py,即可完成反向生成models文件 6.进入models文件进行相关修改 来源: https://www.cnblogs.com/le-le666/p/11802632.html

Using datetime to compare with dates in Django

寵の児 提交于 2019-12-03 13:08:01
问题 I have a question in Django on how you can compare dates to solve some solutions. For example I have a datefield in my models.py Like below. class Invoice(models.Model): payment_date = models.DateTimeField() What I want to be able to do is ask if the is a way to compare a datetime.now with a DateTimeField. For example, if I had a list of payment dates and I wanted to compare with datetime now. Thhe payment_date's that are late with their payments are shown in owing. Otherwise, it the value is

Ruby on Rails Models. Why does a decimal{2,1} with scope 1 allow more than digit after the decimal point?

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm having an issue with a table accepting too many digits after the decimal, despite defining it's precision and scope. rails generate model Hotel name:string 'rating:decimal{2,1}' class CreateHotels < ActiveRecord::Migration def change create_table :hotels do |t| t.string :name t.decimal :rating, precision: 2, scale: 1 t.timestamps end end end However, I am able to do the following. Hotel.create!(name: “The Holiday Inn”, rating: 3.75) Additionally, I have a rooms table (Room model), with t.decimal :rate, precision: 5, scale: 2 #this holds

Django Models - SELECT DISTINCT(foo) FROM table is too slow

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a MySQL table with 13M rows. I can query the db directly as SELECT DISTINCT(refdate) FROM myTable The query takes 0.15 seconds and is great. The equivalent table defined as a Django model and queried as myTable.objects.values(`refdate`).distinct() takes a very long time. Is it because there are too many items in the list before distinct() . How do I do this in a manner that doesn't bring everything down? 回答1: Thank you @solarissmoke for the pointer to connection.queries . I was expecting to see SELECT DISTINCT refdate FROM myTable

ASP MVC 3 Two Models in One View

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am working on creating a datagrid in ASP MVC 3 where I have two tables in one view. Each table is being used from its own Model. Therefore, I would have to call two Models into one View which does not seem as simple as I wish it was. I am pretty new to MVC and I was looking through Stack and found this link: Two models in one view in ASP MVC 3 Which seems to be the direction that i would want to go... I think. Here is the code for my first model: [Table] public class Model1 { [Column(IsPrimaryKey = true, IsDbGenerated = true)] public int

Fitting Markov Switching Models to data in R

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to fit two kinds of Markov Switching Models to a time series of log-returns using the package MSwM in R. The models I'm considering are a regression model with only an intercept, and an AR(1) model. Here is the code I'm using: library(tseries) #Prices ftse<-get.hist.quote(instrument="^FTSE", start="1984-01-03", end="2014-01-01", quote="AdjClose", compression="m") #Log-returns ftse.ret<-diff(log(ftse)) library(MSwM) #Model with only intercept mod<-lm(ftse.ret ~ 1) #Fit regime-switching model msmFit(mod, k=2, sw=c(T,T), p=0, data

ASP .NET MVC - Using a enum as part of the model

筅森魡賤 提交于 2019-12-03 10:20:19
问题 (just learning MVC) I have created a model class: public class Employee { public int ID { get; set; } [Required(ErrorMessage="TM Number is Required")] public string tm_number { get; set; } //use enum? public tmRank tm_rank { get; set; } } The model class refers to the enum 'tmRank': public enum tmRank { Hourly, Salary } When I create a view from this model the 'tm_rank' field does not appear? My hope was that MVC would create a list of the enum values. 回答1: My guess is it doesn't understand

What are the Laravel naming conventions for controllers/models/views?

青春壹個敷衍的年華 提交于 2019-12-03 09:34:05
I remember hearing you should name your controllers, models and views in a special way. Either singular or plural. I don't remember which ones to name what though, and i can't find anything about it in the doc. I'm guessing it's like this: Controllers are plural Views are plural Models are singular Am i on the right track? I understand it's just a convention and you don't have to follow them, but i still want to know what the right way is. In ASP.NET MVC, I use the convention you mentioned above, expect for Views, which are mixed. If I have a view that displays multiple "things", such as a

Creating models in typescript that take injectables

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am creating a user model in typescript, with the following: import {Inject} from 'angular2/core'; import {Http} from "angular2/http"; export class User { firstName:string; lastName:string; constructor(User:User, @Inject(Http) private _http){ this.firstName = User.firstName; this.lastName = User.lastName; } getUserFirstName(){ return this.firstName; } addUser(){ return this._http.post('/api/user/',this); } } And in other places,I use: var use = new User(userObject) // where userObject is an object with firstName and lastName And this

Django ― Models don&#039;t exist, but Django still loads them

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Im getting a ProgrammingError when I try to delete a User object, this is wherever User.delete occurs, it even happens in the admin. The Error Django apparently 'thinks' that there's a relationship between auth_user and apiHandlers_cardholders which doesn't exist anywhere, the database doesn't have a column for this, and there is no models.[y nor admin.py in the app named apiHandlers , but Django expects it to, there is even a section of the Admin site devoted to it. This only started happening when I migrated from SQLite to PostGreSQL. At