models

In cakephp, how can I set conditions for a model that is not associated with the one I am paginating but which is associated to one that is?

I am paginating ($this->Customer->paginate()) on the 'Customer' model. The customer model is associated to the 'Contact' model which in turn is associated to the 'ContactAddress' model. So: Customer hasMany Contact Contact belongsTo ContactAddress Now I want to paginate customers in the 'Customers->index()' using a search query let'...

copy all fields of a django model instance

Hello everybody, ok i think this is very basic, but since i'm new to django i don't know how to handle this.. I need to copy an instance of a django-model. As explained here, there is a problem with copying many2many relations. But the attachment "django-model-copying.diff" has that function i guess. So i don't know - does my django alr...

django : models with reverse foreignkeys?

I've got a chicken and egg problem here. Firstly I've got a userprofile class which builds upon the default user model of django. class UserProfile(models.Model): def __unicode__(self): return self.user.username user = models.OneToOneField(User, unique=True) exam = models.ForeignKey('questions.Exam', null=True) Nex...

Is it better to import controllers or models in CakePHP?

In a CakePHP application, is it better to import Controllers that have access to models or the Models themselves? ...

Localization of Django application only applies to forms.py and not to models.py

I have a problem when trying to localize my application. It is available in two languages: english and german. The problem appears when the browser has the language set english(United States) and in my settings file is set to 'de' and vice-versa. Some fields appear in english, others in german. My model contains CharField, DecimalField a...

How to avoid duplicate models in django project ?

Hi, i'm learning django so i've many questions, and one is how i can reuse a model? i mean the models live in the application folder, but some models are exactly the same between two differents applications. So should i rewrite the model every time that i write a new app? ...

special cakephp model relation

hi, I'm making my first CakePHP project (apart from all the tutorials I did...). I'm making a site for trainers and athletes in the athletics sport. now in my database I have a user table with fields: id, username, firstname, lastname, email, password, ... then I have 2 other tables with the fields: trainers: id, type_id(sprint, dis...

django foreign key save

Hello, I have models for eg like this. class Mp3(models.Model): title=models.CharField(max_length=30) artist=models.ForeignKey('Artist') and Here is how the Artist models looks like: class Artist(models.Model): name=models.CharField(max_length=100,default="Unknown") I have created Artist with id 1. How I can create a mp...

Trying to make comments of comments. How to arrange models?

My :post model is the parent model. Within a post are many comments. And comments have potential of having many more comments, and so forth. I thought I had had this right, but I were to type : Comment.last.comments I get : NoMethodError: undefined method `comments' for #<Comment:0x1053a1ff0> My Models : #comment.rb belongs_to ...

decrease polygon count in Maya

Hello. I'm making models for games. In 3ds Max there was "polygon cruncher" plugin for reducing number of polygons. Is there something similar for Maya? Or is there any other way to do that? ...

Augmenting Bates' `find_commentable` method

I'm watching a Ryan Bates screencast on polymorphic relationships, and he uses this private method for finding all comments related to a nested model. So I could find all the comments of a given Post with this : def find_commentable params.each do |name, value| if name =~ /(.+)_id$/ return $1.classify.constantize.find(value...

How to manage complex models? or just Cache data from database?

My app has windows that are components. In my case, now I have 2 components that have a drop down list that show the current logged user lists. So when I use one component for the first time it make a request to database, save data in model, and load data from model, but when the second component opens, it will just load data from model....

Saving multiple models in CakePHP with saveAll()

Hello, I'm trying to build an invitation system with CakePHP. I have Invitation model which hasMany People, and Person hasOne and belongsTo Invitation. I believe the relationships are working, since my Invitation index view can properly access and display its associated People through the Invitation model. But heres what the relationship...

ActiveRecord: change and save object state inside model

I have the following code: def incoming_acceptation(incoming_code) if invite_code == incoming_code accepted = true self.save true else false end end But it does not change and save accepted to true, it remains in the previous state, false. @i.incoming_acceptation(incoming_code) => true @i.accep...

ASP.NET MVC: How to handle model data that must go to every view?

So if there is some global state that every view of an MVC app will need to render ... for example: IsUserLoggedOn and UserName ... whats the appropriate way of getting that information to every view? I understand that that part of the view should be in the master page or in a partial view thats added to the other views. But whats a goo...

CakePHP: how to use a model in the app_controller

Hi, Iv got a method in a model that I want to be executed everytime a page is requested so I think I need to call it from the app_controller but can't seem to get it to work. The model i want to use is called Blacklist and it has a method in it called check_blacklist() which is what I want to run every time a page is requested. Does anyo...

Should I make a different join table for the same type of relationship?

I have posts that can be voted on by a polymorphic association. Now I am making comments votable as well. Can I share the same models and logic for this for my comments? Or do I have to make a new model relationship ? #post.rb has_many :votes, :as => :votable has_many :...

How does an associated database acquire its foreign key?

I did a bunch of gutting to my default controllers and now I can't get my user_id to populate on create. I was curious how that gets populated. If you're interested, take a look at my routes, and model assocations, and then at then end I'll show you the resulting params..The end result is no user_id being added. routes resources :user...

Load models via bin files in webgl?

I see an example where the data was in text inside an array, i seen another where someone loads the model through ajax with json. Is there a way to load the files via binary? i dont feel like loading a 1mb model via 4mb json ...

Django - CurrentUserField

I was just exploring http://code.djangoproject.com/ticket/1132 I am receiving 'undefined' error while using 'models.CurrentUserField' . Is this supported by Django 1.2.3? ...