model

How do I get the values of the lastest entries grouped by an attributes using Django ORM?

I have a report model looking a bit like this: class Report(models.Model): date = models.DateField() quantity = models.IntegerField() product_name = models.TextField() I know I can get the last entry for the last year for one product this way: Report.objects.filter(date__year=2009, product_name="corn").order_by("-date")[0...

Google App Engine: Model integrity constraints?

I have a datastore model representing items in an ecommerce site: class Item(db.Model): CSIN = db.IntegerProperty() name = db.StringProperty() price = db.IntegerProperty() quantity = db.IntegerProperty() Is there some way to enforce integrity constraints? For instance, I would like to make sure that quantity is never s...

Ruby on Rails - Access controller variable from model

Hey, I am trying to access an instance variable which is set in the controller in the model. The controller is the products controller and the model is the products model. The instance variable is a instance of another model called account. The instance variable is @current_account When I run the code nothing happens, I do not get an ...

What is the best way to store data in an objective-c model?

I am writing an objective-c model to hold all of the data parsed from an XML connection. I am using an NSURLConnection to download the data asynchronously and it is then passed to the parser. I have done this before, but not with such a large xml file. I would like to garner some opinions on the best way to store the data. Here are s...

Options for keeping models and the UI in sync (in a desktop application context)

In my experience I have only had 2 patterns work for large-scale desktop application development when trying to keep the model and UI in sync. 1-An eventbus approach via a shared eventbus command objects are fired (ie:UserDemographicsUpdatedEvent) and have various parts of the UI update if they are bound to the same user object updated ...

Binding a list belonging to another object in a custom model binder in ASP.NET MVC

I realize something like this has been asked, but this may be a little different Below is my Event object: Event : IEvent public int Id public string Title public List<EventContact> Contacts And EventContact: EventContact public int Id public string Name public string Email So, an Event has a list of EventContact objec...

General approach for posting business logic status messages to UI?

Hello all. I have been struggling with this question for awhile now, and I haven't reached a conclusion. I'm not typically a UI programmer, so forgive the noobishness. I'm writing a typical application with a UI layer (WPF) and a business layer. I want to post status messages to the UI from the business layer (perhaps deep within the...

Rails Tableless Model

I'm creating a tableless Rails model, and am a bit stuck on how I should use it. Basically I'm trying to create a little application using Feedzirra that scans a RSS feed every X seconds, and then sends me an email with only the updates. I'm actually trying to use it as an activerecord model, and although I can get it to work, it doesn...

Django: How to dynamically add tag field to third party apps without touching app's source code

Scenario: large project with many third party apps. Want to add tagging to those apps without having to modify the apps' source. My first thought was to first specify a list of models in settings.py (like ['appname.modelname',], and call django-tagging's register function on each of them. The register function adds a TagField and a cus...

Report Model; problem regarding many-to-many relations

I'm having trouble setting up a report model to create reports with report builder. I guess I'm doing something wrong when configuring the report model, but it might also due to change of primary entity in report builder. I have 3 tables: Client, Address and Product. The Client has PK ClientNumber. The Address and Product both have a FK...

django ManyToMany through help

Hay I've got a question about relationships. I want to Users to have Friendships. So a User can be a friend with another User. I'm assuming i'll need to use the ManyToManyField, through a Friendship table. But i cannot get it to work. Any ideas? Here are my models. class User(models.Model): username = models.CharField(max_length=9...

Proper method to detect device model (iPhone/iPod Touch)?

Is this the proper way to detect which device a user is running? NSString *currentModel = [[UIDevice currentDevice] model]; if ([currentModel isEqualToString:@"iPhone"]) { // The user is running on iPhone so allow Call, Camera, etc. } else { // The user is running on a different device (iPod / iPad / iPhone Simulator) disallow C...

Django save_m2m() and excluded field

UPDATE: I ended up creating a new forms.Form instead of using a ModelForm hi, in a ModelForm I replaced a field by excluding it and adding a new one with the same name, as shown below in AddRestaurantForm. When saving the form with the code shown below, I get an error in form.save_m2m() ("Truncated incorrect DOUBLE value"), which seems...

and or operator in validates_presence_of of a Ruby on Rails model

I have an entry.rb model and I'm trying to make a semi-complicated validation. I want it to require one or more of the following fields: phone, phone2, mobile, fax, email or website. How would you write the intended code? Would something like this work? validates_presence_of :phone and or :phone2 and or :mobile and or :fax and or :email...

Model responsibilities in MVVM

Is Model only Entity Data Model class of my database? Model as simple place where i have my data? Or I can input in Model something more? ...

A few questions about a Rails model for a simple addressbook app

I have a Rails application that lists information about local services. My objectives for this model are as follows: 1. Require the name and tag_list fields. 2. Require one or more of the tollfreephone, phone, phone2, mobile, fax, email or website fields. 3. If the paddress field has a value, then encode it with the Geokit plugin. Here i...

CakePHP: Field label in model

Are there any approaches to set in model field label? I dont want use 'label' property in form helper. ...

Howto UML: sub methods / calls / operations / procedures

I'm not sure how to model sub-methods in UML sequence diagram. When in the execution of one method another method is called (from the same class). I tried to give an example below: How would you guys model this in UML (in a sequence diagram)? .. car1.drive(); .. ... in Car class: .. drive(){ this.startEngine(); } startEngine(){ ...

Kohana 3: Example of model with validation

I find examples and tutorials about models and about validation. And I places that say the validation (or most of it at least) should be in the model, which I agree with. But I can't any examples or tutorials that show how that should be done. Could anyone help me with a simple example on how that could be done? Where would you have th...

Rails has_many with dynamic conditions

Hello! What I want is to create a Model that connects with another using a has_many association in a dynamic way, without the foreign key like this: has_many :faixas_aliquotas, :class_name => 'Fiscal::FaixaAliquota', :conditions => ["regra_fiscal = ?", ( lambda { return self.regra_fiscal } ) ] But I get the error: : SE...