models

What is the best / proper idiom in django for modifying a field during a .save() where you need to old value?

Hi, say I've got: class LogModel(models.Model): message = models.CharField(max_length=512) class Assignment(models.Model): someperson = models.ForeignKey(SomeOtherModel) def save(self, *args, **kwargs): super(Assignment, self).save() old_person = #????? LogModel(message="%s is no longer assigned to ...

ContentType Issue -- Human is an idiot - Can't figure out how to tie the original model to a ContentType abstracted 'Favorite' model

Originally started here: http://stackoverflow.com/questions/2650181/django-in-query-as-a-string-result-invalid-literal-for-int-with-base-10 I have a number of apps within my site, currently working with a simple "Blog" app. I have developed a 'Favorite' app, easily enough, that leverages the ContentType framework in Django to allow me ...

Best way to handle multiple tables to replace one big table in Rails? (e.g. 'todo_items1', 'todo_items2', etc., instead of just 'todo_items')?

Update: Originally, this post was using Books as the example entity, with Books1, Books2, etc. being the separated table. I think this was a bit confusing, so I've changed the example entity to be "private todo_items created by a particular user." This kind of makes Horace and Ryan's original comments seem a bit ...

Sharing Models between two Rails Projects - using git submodules?

I have a Rails website which has been divided into two separate projects - the public site, and the administration site. As both sites are using the same database the models are shared between the applications (actually right now they are duplicated). The problem I have here is that when an update to the models occurs in the public proj...

What is the best way to setup my tables and relationships for this use case?

1)A user can have many causes and a cause can belong to many users. 2)A user can have many campaigns and campaigns can belong to many users. Campaigns belong to one cause. I want to be able to assign causes or campaigns to a given user, individually. So a user can be assigned a specific campaign. OR a user could be assigned a cause and...

How can I iterate through all of the Models in my rails app?

I would like to be able to iterate over and inspect all the models in my rails app. In pseudo-code it would look something like: rails_env.models.each do |model| associations = model.reflect_on_all_associations(:has_many) ... do some stuff end My question is how do I inspect my rails app to get a collection of the models (ra...

Django models: Use multiple values as a key?

Here is a simple model: class TakingCourse(models.Model): course = models.ForeignKey(Course) term = models.ForeignKey(Term) Instead of Django creating a default primary key, I would like to use both course and term as the primary key - taken together, they uniquely identify a tuple. Is this allowed by Django? On a related not...

Django: ManyRelatedManager is not Callable

I have a site with users who can take terms at University: class Term(models.Model): school = models.ForeignKey(School) name = models.CharField(max_length=200) isPrimaryTerm = models.BooleanField() date = models.DateField() class MyUser(models.Model): user = models.ForeignKey(User, unique=True) takingReqSets = m...

ASP MCV multi-view form models

I am pretty new to this stuff but I am running into a concept-wall and I keep going back and forth with the best way to handle the problem. I have a multi-view process to filling out a "New User Form". Each view has a small part of the entire form. In each view I have a model and the model has properties set to an instance of a LINQ to...

Modifying Model data in beforeSave of Behavior when using saveAll

I'm trying to write a Meta behavior for a project I am working on that will allow me to assign custom variables/attributes to a model, similar to how you can create custom fields in a wordpress post. I have created a Meta behavior that binds the meta model to the model it is acting on and also has a beforeSave callback that loops throug...

Trying to understand MVC Models, Advice?

I am writing my own MVC for the purpose of learning it. I have pretty much everything "down-pat" and my main stuff written besides models due to some trouble understanding them and lack of viable examples. Now, I've been told a model should reprecent a single row, someone told me, your model class should on update/insert and delete rows...

Source code to class diagram generation

How can I generate a class diagram and other related modeling diagrams from source code ? I am open to any tool (Eclipse plug-in etc) but does Netbeans has a plugin for it too? ...

Passing arguments and conditions to model in codeigniter

I'm adding some models to a project, and was wondering if there is a "best practice" kind of approach to creating models: Does it make sense to create a function for each specific query? I was starting to do this, then had the idea of creating a generic function that I could pass parameters to. e.g: Instead of function getClients(){...

Change model name in rails easily

I'm going to need to change one of my model names. Is there anything out there that will replace every instance of the original model name in the controllers views and tests or do I have to do it all manually, page by page? ...

How can I display a list of three different Models sortable by the same :attribute in rails?

I have a Campaign model which has_many Calls, Emails, and Letters. For now, these are each a separate Model with different controllers and actions (although I would like to start to think of ways to collapse them once the models and actions stabilize). They do share two attributes at least: :days and :title I would like a way to repre...

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

Hi 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 ...

Organizing a lot of models that use STI in rails

I have a scenario where I am going to be creating a large number of models that use STI and I'm wondering what the best way to organize this is. I already have other models using STI and I really do not want to add any more files to my models folder. Is there any way to create a folder and add the models using STI there (there could be...

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 until the record saves, therefore I can't use validates_presence_of :project_id. So my que...

Rails link from one model to another based on db field?

Hi Everyone, I have a company model and a person model with the following relationships: class Company < ActiveRecord::Base has_many :kases has_many :people def to_s; companyname; end end class Person < ActiveRecord::Base has_many :kases # foreign key in join table belongs_to :company end In the create action for the perso...

CakePHP: Using two tables for a single model

I'm just picking up development in CakePHP right now so forgive me if this seems obvious; it did to me when I first read about has, belongsTo, hasMany, etc. The problem is I would like to associate two tables with a single model, and was wondering if there was a way to configure this so that when CakePHP did it's queries it automaticall...