I have the following code in a layout:
Posted <%=time_ago_in_words post.created_at %> ago
<% if post.has_tag != nil %>
in the <%= post.get_first_tag.name %> category
<% end %>
And the following code in the post model which is inheriting form ActiveRecord::Base
def has_tag
!self.tags.empty?
end
def get_first_tag
self.tags[0]...
Hello, i have Ruby class:
class Migrator
def self.migrate_old_categories
ActiveRecord::Base.establish_connection(:data_center_v2)
ActiveRecord::Base.table_name = "categories"
end
end
I need use it, as i used it always. For example: Category.find(:all)
So, how i can it, when i'm write: Migrator.migrate_ol...
I can force to inlcude one model by
Yii::import("application.models.modelName", true);
What should I do to include all models from models directory?
Line:
Yii::import("application.models.*", true);
doesn't work becouse yii import only when there is need to use it.
...
I have a model as follows:
Campaign
has_many :companies, :through => :contacts
There are many contacts with the same company. I just want one instance of each company.
I tried the following:
@campaign = Campaign.find(params[:id])
@companies = @campaign.companies
But this shows me all the companies for every contact I believe. ...
Hello i'm in the process of creating my first site in ASP.NET MVC, it is a kind of learn as you go. But i have hit a problem that i just can't find a solution for.
I want my user to be able to create an album with songs and tags attached.
That can be an unspecified number of songs and tags. But there must be a minimum of 5 songs and 2 t...
I have a whole host of models that watch themselves for changes. When a setter is triggered, the observer in the model is called and within that model I make a call to a web server and update information in the web server so it correctly has the data it should.
However, in my call to the web server I can get back an error for anything f...
I came across this syntax browsing through code for examples. From its surrounding code, it looked like would a) get the entity with the given keyname or b) if the entity did not exist, create a new entity that could be saved. Assume my model class is called MyModel.
my_model = MyModel(key_name='mymodelkeyname',
kwa...
You can create a new model in App Engine using a dictionary:
my_model = MyModel.get_or_insert(keyname, **kwargs)
Is there a way to update a model using a dictionary instead of doing the following?
my_model.firstprop = 'first'
my_model.secondprop = 'second'
...
Hi,
I'm writing a small Django-based frontend to collect and graph internet usage statistics.
Currently, from our ISP, we get monthly text files that show the average bytes/second for every 5-minute interval. E.g.:
Date Time In Out
28.03.2010 00:00:00 204304 228922
28.03.2010 00:05:00 104231 222998
28.03.2010 00:10...
Hi,
I have been busy with the cakePHP framework for a couple of months now and I really love it. At the moment I'm working on a very new project and it does the job like it should (I think ...) but I feel uncomfortable with some code I wrote. In fact I should optimize my paginate conditions query so I get immediately the right results ...
The end goal is to create a helper found at the end called show_status(contact,event).
Event can be any object, Email, Letter, etcetera. The combination of an Email template sent to a Contact is a specific record ContactEmail. Because each event has a different corresponding Model I need to do the .find on, I have duplication. There ...
I am using Memcached as an Object Store with my Rails application where I store search results which are User objects in memcached
Now when I fetch the data out I get the Memcached Undefined Class/Module Error. I found a solution for this problem in this blog
http://www.philsergi.com/2007/06/rails-memcached-undefinded-classmodule.html...
I previously had models like this:
class AssemblyAnnotation(models.Model):
assembly = models.ForeignKey(Assembly)
type = models.ForeignKey(AssemblyAnnotationType)
...
def clean(self):
from django.core.exceptions import ValidationError
if not self.type.can_annotate_aliases and self.assembly.alias_of_id is ...
I currently have the following code:
events.detect do |event|
#detect does the block until the statement goes false
self.event_status(event) == "no status"
end
What this does is output the instance of event (where events is a string of different Models that all collectively call Events) when the event_status method outputs a "no ...
I'm building a site that requires multiple forms for the same model in varying numbers throughout a single page. These forms belong to an object with an id. Currently, since I can't figure out how to change the form ids, I'm stuck with a hole bunch of duplicate ids.
I'm looking for a way to append the object id to the form id so they're...
I need select rows with django orm. I need equivalent of such query
select * from order where (user_from = u and f1 not is null) or (user_to = u and f2 not is null)
I try to do this way:
Order.objects.filter(user_from = self).exclude(f1 = None)+Order.objects.filter(user_to = self).exclude(f2 = None)
But no union in orm.. how can be...
I like using Models for validation
<!-- ViewPage -->
<%@ Page Language="C#" Inherits="ViewPage<TopicModel>" %>
...
<%= Html.TextBoxFor(m => m.Title) %>
...
<%= Html.TextBoxFor(m => m.Description) %>
// Controller
[HttpPost]
public ActionResult NewTopic(TopicModel model)
{
// validate
}
It works great, but when I need to p...
...or why did they fail?
I am going to build a proof of a concept of something which could be classified as CASE, but I want to avoid some of the mistakes done before.
Thanks!
...
Hi, I have a ManyToManyField in a model which uses the 'through' option. Using a Django ModelForm, this seems to be failing giving me a funny error about having to use the model's manager.
I want to be able to edit this inline (i think the admin lets me do this) and looked up it on google, but everything to use this Django Inline Forms ...
Hi again,
I have a simile timeline built and I want to use the data from some django models.
I would like to known if is best to use XML or JSON.
I don't known anything about any of the two, so if I have to learn, it's best to known which will do what I want.
I will need to make some loops to iterate over the data and use variables.
...