Questions tagged [models]

A model is an abstract representation of a real-life object or process. Models are a part of the popular MVC pattern, as well as a more general concept in the sciences for approximating behavior.

A model is one of the three components of Model-View-Controller (MVC) programming pattern that provides knowledge: data and how to work with this data, responding to requests by changing its state.

It can also refer to models in a more general scientific sense, denoting a representation (generally a simplification) of how a real-world process operates.

2397 questions
31
votes
2 answers

Rails put validation in a module mixin?

Some validations are repetitive in my models: validates :name, :length => { :minimum => 2 }, :presence => true, :uniqueness => true validates :name_seo, :length => { :minimum => 2 }, :presence => true, :uniqueness => true How would I put that in a…
Victor Pudeyev
  • 4,296
  • 6
  • 41
  • 67
29
votes
5 answers

Best way to make one model 'selected' in a Backbone.js collection?

I have a collection of models in my Backbone.js application. It's a list of items that you can hover over with the mouse or navigate around with the keyboard. If the mouse is hovering, or if the keyboard navigation has the item selected they will…
littlejim84
  • 9,071
  • 15
  • 54
  • 77
29
votes
1 answer

ES6 Classes for Data Models

I'm trying to use ES6 Classes to construct data models (from a MySQL database) in an API that I'm building. I prefer not using an ORM/ODM library, as this will be a very basic, simple API. But, I'm struggling to get my head around how to define…
go4cas
  • 1,171
  • 5
  • 14
  • 27
27
votes
1 answer

How to use different authentication_keys for two devise models?

Now I have one devise model, which uses email as authentication_key. I want to add one new devise model, which uses student_id as authentication_key. Some guide tells me to modify the configuration "config.authentication_keys = [ :email ]" by…
Roy
  • 271
  • 3
  • 3
26
votes
4 answers

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

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…
qwerty
  • 5,166
  • 17
  • 56
  • 77
26
votes
1 answer

Django MVC pattern for non database driven models?

I'm just working my way through Django, and really liking it so far, but I have an issue and I'm not sure what the typical way to solve it. Suppose I have a View which is supposed to be updated when some complex Python object is updated, but this…
DevDevDev
  • 5,107
  • 7
  • 55
  • 87
25
votes
1 answer

Trigger Odoo fields_view_get dynamically after all records being loaded and fields_view_get function called

I’d like to trigger the fields_view_get function dynamically after doing some functions. I override the function fields_view_get and return my results. This gets affected on XML view only at first time the actual function called. So I need to…
Hilar AK
  • 1,655
  • 13
  • 25
25
votes
12 answers

Spacy link error

When running: import spacy nlp = spacy.load('en') the following is printed: Warning: no model found for 'en' Only loading the 'en' tokenizer. /site-packages/spacy/data is empty with the exception of the init file. all filepaths are only…
negfrequency
  • 1,801
  • 3
  • 18
  • 30
24
votes
3 answers

Sequelize: seed with associations

I have 2 models, Courses and Videos, for example. And Courses has many Videos. // course.js 'use strict'; module.exports = (sequelize, DataTypes) => { const Course = sequelize.define('Course', { title: DataTypes.STRING, description:…
zett
  • 397
  • 1
  • 2
  • 8
24
votes
3 answers

Django models filter by foreignkey

I'm having some trouble in filtering objects from a set of models. Here is the problem: I have 3 classes: class Autor(models.Model): nome = models.CharField(max_length=50) slug = models.SlugField(max_length=50, blank=True, unique=True) …
maloky
  • 343
  • 1
  • 2
  • 6
23
votes
1 answer

How do Django Fixtures handle ManyToManyFields?

I'm trying to load in around 30k xml files from clinicaltrials.gov into a mySQL database, and the way I am handling multiple locations, keywords, etc. are in a separate model using ManyToManyFields. The best way I've figured out is to read the data…
CMaury
  • 1,273
  • 5
  • 13
  • 25
23
votes
7 answers

Rails: validate presence of parent_id in has_many association

I have a projects resource that has many tasks. I want to ensure that every task has a project_id by adding validates_presence_of :project_id to the tasks model. However, when creating a new project with tasks, the project_id won't be available…
deb
  • 12,326
  • 21
  • 67
  • 86
23
votes
2 answers

Can you add parameters to Django custom admin actions?

For example (not the case, but just to illustrate) if I wanted to add an action to set a specific field in the selected items to X. Is it possible to add an action to allow X to be entered as opposed to hard coded?
nickponline
  • 25,354
  • 32
  • 99
  • 167
21
votes
2 answers

How to determine if a table relationship is bidirectional or unidirectional in Doctrine 2?

I am in the process of upgrading from Doctrine 1.1.4 to Doctrine 2.0.6 in my Zend application. Currently, I am working on mapping the associations between entities. In Doctrine 2's Documentation it says 'relationships maybe bidirectional or…
Mr B
  • 3,980
  • 9
  • 48
  • 74
21
votes
4 answers

How to assign items inside a Model object with Django?

Is it possible to override values inside a Model? I am getting 'MyModel' object does not support item assignment. my_model = MyModel.objects.get(id=1) print my_model.title if my_model.is_changed: my_model['title'] = 'something' # 'MyModel'…
Pompeyo
  • 1,459
  • 3
  • 18
  • 42