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
20
votes
4 answers

Compare two lists of object for new, changed, updated on a specific property

I've been trying and failing for a while to find a solution to compare to lists of objects based on a property of the objects. I've read other similar solutions but they were either not suitable (or I didn't understand the answer!). Code is C# I…
user3313496
  • 323
  • 1
  • 2
  • 7
19
votes
3 answers

How do I specify shared attributes translations between models in I18n locale file?

I tried the following: es: activerecord: attributes: name: Nombre And it did not work. But the following do work: es: activerecord: attributes: person: name: Nombre Which is the correct way to define default…
Zequez
  • 3,399
  • 2
  • 31
  • 42
19
votes
4 answers

Creation of dynamic model fields in django

This is a problem concerning django. I have a model say "Automobiles". This will have some basic fields like "Color","Vehicle Owner Name", "Vehicle Cost". I want to provide a form where the user can add extra fields depending on the automobile that…
thestudent
  • 251
  • 1
  • 4
  • 5
19
votes
4 answers

Overriding default_scope in Rails

In my Post.rb model, I have default_scope :conditions => {:deleted => 'false'} But if I try to run Post.find(:all, :conditions => "deleted='false'"), it won't return anything. It's as if the default_scope takes precedence over everything. I want…
Jess
  • 3,111
  • 3
  • 22
  • 17
18
votes
3 answers

When to split up models into multiple database tables?

I'm working with Ruby on Rails, but this question I think is broader than that and applies to database design generally. When is it a good idea to split a single model up into multiple tables? For example, assume I have a User model, and the number…
William Jones
  • 18,089
  • 17
  • 63
  • 98
17
votes
2 answers

Roll back all rails migrations or drop tables and modify migrations (start from scratch)

I'm new to Rails and have started a project that I'm unhappy with my models and db schema. I'd like to start again from scratch but keep all my views, controllers. What's the best way to go about doing this? I want to remove all my migrations and…
AdamT
  • 6,405
  • 10
  • 49
  • 75
17
votes
3 answers

How to run multiple graphs in a Session - Tensorflow API

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…
saikishor
  • 878
  • 3
  • 11
  • 21
17
votes
1 answer

is a ModelChoiceField always required?

I have a model class Article(models.Model): . . language = models.ForeignKey(Language, help_text="Select the article's language") parent_article = models.ForeignKey('self', null=True, blank=True) If an article is an original article…
Henri
  • 875
  • 2
  • 14
  • 22
17
votes
2 answers

Creating Qt models for tree views

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…
Veeti
  • 5,270
  • 3
  • 31
  • 37
16
votes
2 answers

Inserting NULL as default in SQLAlchemy?

I have the following column in SQLAlchemy: name = Column(String(32), nullable=False) I want that if no value is passed onto an insertion, it should enter a default value of either completely blank or if not possible, then default as NULL. Should I…
sshussain270
  • 1,785
  • 4
  • 25
  • 49
16
votes
2 answers

How to set value of a ManyToMany field in Django?

while learning Django to do web programming,I faced this problem. I searched Google and Django's official website biut could not find any answer. Please help me. System environment: Fedora 18 Python 2.7 Django 1.5.1 Eclipse + PyDev Runtime:…
kidney win
  • 361
  • 1
  • 2
  • 15
16
votes
3 answers

Rails Validation for users email - only want it to validate when a user signs up or updates email address

I have a User model with the usual attributes such as email and hashed_password etc. I want to write a validation that checks for the presence of an email address but only when 1) there isn't one stored in the database for this object (i.e. this is…
robodisco
  • 4,162
  • 7
  • 34
  • 48
15
votes
1 answer

Extending Eloquent Models in Laravel (use different tables)

I’m building a Laravel application that involves tracking different types of leads. For example, there are Refinance leads and Purchase leads. Since the leads share a lot of information and functionality, but not all, my thinking was to create a…
jackel414
  • 1,636
  • 2
  • 13
  • 29
15
votes
5 answers

How to create a normal sails model without being in the models folder

So, I'm in the middle of implementing a plugin api for my application, and the plugins can have their own models, imagine this. SimplePlugin = { pluginName: 'simple', pluginConfig: {}, SimpleModel: { attributes: { …
iConnor
  • 19,997
  • 14
  • 62
  • 97
15
votes
1 answer

django-mutant creating models in django-admin

I started experimenting with django-mutant 0.0.2 (on django 1.4.2), but due to the lack of documentation I got almost nowhere. The way I understood by the project description I could use it to create my models dynamically, so I thought I can wire it…
andrean
  • 6,717
  • 2
  • 36
  • 43