models

Custom Managers and "through"

Hi I have a many-to-many relationship in my django application where I use the "add" method of the manager pretty heavily (ie album.photos.add() ). I find myself needing to store some data about the many-to-many relationship now, but I don't want to lose the add method. Can I just set a default value for all the additional fields on th...

Zend Framework Models

I'm trying to understand how the Zend Framework works.Are the models designed to do something like this?I have just a basic setup, so I can use in my controllers something like this: $db->query($this->selectAll()) Can you also give me an example on how to use this on a controller? class Country extends Zend_Db_Table { protected ...

Trying to define named_scopes and other ActiveRecord relationships on all models.

I'm trying to define a named_scope for all my models in a Rails application. Presently, I've been able to get close to this by writing an initializer for ActiveRecord::Base and putting regular methods in there. Of course, this offers no real advantage when it comes to creating query chains and is probably the least rails-ey way of getti...

How to access non-child models from other controller in CakePHP ?

Hey folks, i got trouble finding information about how to use model that doesnt belong to controller. Lets see, for example: i have ajax controller, that performs only JSON data to application, and it supposed to access different models depending on request. So, how can i do it ? ...

Django ORM equivalent

Hi all, I have the following code in a view to get some of the information on the account to display. I tried for hours to get this to work via ORM but couldn't make it work. I ended up doing it in raw SQL but what I want isn't very complex. I'm certain it's possible to do with ORM. In the end, I just want to populate the dictionary a...

models.py getting huge, what is the best way to break it up?

Directions from my supervisor: "I want to avoid putting any logic in the models.py. From here on out, let's use that as only classes for accessing the database, and keep all logic in external classes that use the models classes, or wrap them." I feel like this is the wrong way to go. I feel that keeping logic out of the models just to ...

Is there a tool to determine which Cognos 8.x models are being used?

We have a Cognos 8.x installation with hundreds of reports and dozens of models. We believe that many of the models are not currently in use on any reports and want to remove those models. Are there any tools that can be run against Cognos to list which reports are using which model? ...

When is MVC no longer applicable in large projects?

Having used some PHP frameworks such as Codeigniter and Kohana for some smaller sites, I'm starting to wonder if MVC is still applicable for larger projects and, if so, what precautions need to be taken to maintain clean clode. What practices do the larger sites use in order to prevent this? Does Amazon's or Flickr's code use MVC or some...

Application / MVC Event Model

Update: This question was inspired by my larger quest for mapping ontologically the whole software systems architecture enchilada. I've written a blog post about it, and hopefully it will help clarify what I'm after. Many, many, many frameworks and stacks that's event-driven have too much variation for my little head to get around. Is...

ASP.NET MVC - model decision: how to design it?

This is concerning an enterprise application with a very generic database (all objects are identified using data in the database and internationalized/globalized/localized). Make a model for Repository pattern, then make (generate 1:1) another model for DB access (LINQ2SQL or EF) and use the later as repository model data access layer?...

Cache all models in a table

I need to cache (and expire) all the models in a table. For example, if i have a model named Currency, i only have less than 10 possible currencies. Therefore, it would be nice to have: class Currency < ActiveRecord::Base cache_all(:expire_in => 10.minutes) end so that Currency.all Currency.find_by_name("USD") should not hit the...

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 object is not driven by the database, say it is driven by AJAX calls or directly by the use...

Django empty field fallback

Hi there, I have a model that holds user address. This model has to have first_name and last_name fields since one would like to set address to a recipient (like his company etc.). What I'm trying to achieve is: if the fist_name/last_name field in the address is filled - return simply that field if the fist_name/last_name field in the...

ASP.NET MVC "Models" directory: What is it good for?

The default ASP.NET MVC project sets up a "Models" directory that I don't know that I've ever used in the handful of MVC projects I've worked on. Normally, I have a separate 'library' project that stores business logic classes. Now I'm curious: Am I missing something big by not taking advantage of the default ASP.NET "Models" director...

Diff django model objects with ManyToMany fields

I have a situation where I need to notify some users when something in DB changes. My idea is to catch pre_save and post_save signal and make some kind of diff and mail that. Generally it works good, but I don't know how to get diff for m2m fields. At the moment I have something like this: def pre_save(sender, **kwargs): pk = kwar...

Collection_select problem

UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from BushyMark. I think I made all the suggested changes correctly, but I still can't get the post_type_id to save to the database when a user submits a message. My app has a profile page. On the profile page, the owner of the page can type an update and...

ListProperty of keys vs Many-to-Many in App Engine

As a hypothetical example, I have a model TodoItem and a model TodoList. An TodoList has an ordered list of TodoItems, and any one TodoItem can belong to any number of TodoLists (Many-to-Many). No other information needs to be stored about their relationship other than the order of a TodoItem in a TodoList. What is the best way to repr...

Friendly URL Question, with a Twist

I have a user model and a profile model. user has_one :profile profile belongs_to :user Because of this relationship, I pull up my profiles by calling the user id. So my urls look like this: website.com/users/[user_id]/profile I'm not sure if there's a solution to my problem. Here it is: I would like to display SEO friendly urls. I'...

Querying django ManyToMany

I have got Foo <=> FooGroup <=> Bar relation, where <=> stands for ManyToMany field. How do I retrieve all the Foos for a specific Bar instance? ...

Composite Application guidance (PRISM) and Models

Where in the solution/projects, should I put the models for the data access layer. For example, if I have a login module that needs to use a Users table in a database, and I have a User.cs model. Where would that file go. If other modules need to be able to access this User.cs for information, then I cannot put it in the module. But then...