models

Rails: how to require at least one field not to be blank

随声附和 提交于 2019-12-28 09:14:07
问题 I know I can require a field by adding validates_presence_of :field to the model. However, how do I require at least one field to be mandatory, while not requiring any particular field? thanks in advance -- Deb 回答1: You can use: validate :any_present? def any_present? if %w(field1 field2 field3).all?{|attr| self[attr].blank?} errors.add :base, "Error message" end end EDIT: updated from original answer for Rails 3+ as per comment. But you have to provide field names manually. You could get all

How do I make sure that my do button will mark the specific task as requested do.

五迷三道 提交于 2019-12-25 18:47:19
问题 I have tasks listed and each task has both a "Do" button and a "Fund" button. Once I click on the "Do" button or "fund" button, I want the specific task to be assigned to a state of "DoRequested" or "FundingProposed". I just do not know how to add these states to the specific model in my case. As I am new to angular, I have no idea on how to do this. Here is my view code so far: <div ng-app="facebookExample" view-title="Tasks"> <div ng-controller="todoController"> <h1>Tasks</h1> <div class=

How to choose the best model dynamically using python

帅比萌擦擦* 提交于 2019-12-25 18:25:46
问题 Here is my code im building 6 models and i am getting accuracy in that, how do i choose that dynamically which accuracy is greater and i want to execute only that model which as highest accuracy. "prepare configuration for cross validation test harness" seed = 7 "prepare models" models = [] models.append(('LR', LogisticRegression())) models.append(('LDA', LinearDiscriminantAnalysis())) models.append(('KNN', KNeighborsClassifier())) models.append(('CART', DecisionTreeClassifier())) models

Cakephp 2.8.4 ignoring hasMany

╄→гoц情女王★ 提交于 2019-12-25 07:38:18
问题 This is a very odd issue that I have not been able to figure out for a very long time. I have a model Upload , with several hasMany all being ignored by UploadModel . For example. Upload hasMany Face . On comments table I have a field called foreign_key that hosts the Upload.id. So the relationship in UploadModel looks like this: $hasMany = ['Face' => ['foreignKey' => 'Face.upload_id']]; When performing a find in Upload with contain Face + conditions [Face.celebrity_id = 4018] I get the

Using a function from a model in a controller/view in Laravel

。_饼干妹妹 提交于 2019-12-25 07:37:26
问题 I am trying to access data from a query that I have placed within a function in a model. I am trying to call the function within a controller, and then send along that data to a view. So far, I have been unsuccessful. Here is the code: Model: Fanartist.php public function fan_likes() { $fan_likes = DB::table('fanartists') ->join('artists', 'fanartists.fan_id', '=', 'artists.id') ->where('fanartists.fan_id', '=', Auth::user()->id) ->select('artists.id', 'artists.stage_name', 'artists.city',

Confused about working with nested models in Titanium Alloy

空扰寡人 提交于 2019-12-25 07:08:52
问题 The goal is simple. My app has a messaging component. The way I'm planning on structuring it is by having a Conversation model, which has some attributes (subject, start date, uID), and each Conversation will contain many Message models. Conceptually what I'm trying to do seems pretty trivial: have a Collection of Conversations bound to a TableView. When a table view is clicked, the nested messages get bound to a new Window. I'm struggling with how to do this via Backbone. I have experience

Cross uniqueness model validation in rails

独自空忆成欢 提交于 2019-12-25 06:04:15
问题 I have a model where I want columns to contain different ids. So a user may follow another user, but not follow themselves. Migration class CreateFollows < ActiveRecord::Migration def change create_table :follows do |t| t.integer :follower_id t.integer :followee_id t.timestamps end end end Model class Follow < ActiveRecord::Base belongs_to :follower, class_name: 'User' belongs_to :followee, class_name: 'User' validates :follower_id, uniqueness: { scope: :followee_id } end But my test seems to

how to find height and width of image for FileField Django

半世苍凉 提交于 2019-12-25 04:48:07
问题 How to find height and width of image if our model is defined as follow class MModel: document = FileField() format_type = CharField() and image is saved in document then how we can find height and width of a document if it is image ? 回答1: If the files will always be images, change FileField to ImageField, like this: def MyModel(models.Model): height = models.IntegerField() width = models.IntegerField() document = models.ImageField(height_field='height', width_field='width') Otherwise, you'll

Laravel: Create or update related model?

爱⌒轻易说出口 提交于 2019-12-24 13:41:46
问题 Please be gentle with me - I'm a Laravel noob. So currently, I loop through a load of users deciding whether I need to update a related model (UserLocation). I've got as far as creating a UserLocation if it needs creating, and after a bit of fumbling, I've come up with the following; $coords = $json->features[0]->geometry->coordinates; $location = new UserLocation(['lat'=>$coords[1],'lng'=>$coords[0]]); $user->location()->save($location); My issue is that one the second time around, the

How to modify layers of pretrained models in Keras like Inception-v3?

谁说我不能喝 提交于 2019-12-24 13:33:55
问题 I want to use Inception-v3 with pretrained weights on ImageNet to take inputs that are not just 3 channel RGB images but have more channels, such that the dimension is (224, 224, x!=3) , and then assigning a self-defined set of weights to the following Conv2D layer. I was trying to change the input layer and the subsequent Conv2D layer such that it suits my needs, but I could not find a structured way of doing so. I tried building a custom Conv2d tensor with Conv2D(...)(input) and assigning