Search Results

Search found 15231 results on 610 pages for 'presentation model'.

Page 55/610 | < Previous Page | 51 52 53 54 55 56 57 58 59 60 61 62  | Next Page >

  • Best way to model map values in Grails?

    - by Mulone
    Hi guys, I have to implement map values in my Grails app. I have a class that can contain 0..N OsmTags, and the key is unique. In Java I would model this with a Map in each object, but I don't know how to map classes in Grails. So I defined this class: class OsmTag { /** OSM tag name, e.g. natural */ String key /** OSM tag value, e.g. park */ String value static constraints = { key blank:false, size:2..80,matches:/[\S]+/, unique:false value blank:false, size:1..250,matches:/[\S]+/, unique:false } } That works ok, but it's actually quite ugly because the tag key is not unique. Is there a better way to model this issue? Cheers

    Read the article

  • Ruby on Rails activerecord find average in one sql and Will_Paginate

    - by Darkerstar
    Hi all I have the following model association: a student model and has_many scores. I need to make a list showing their names and average, min, max scores. So far I am using student.scores.average(:score) on each student, and I realise that it is doing one sql per student. How can I make the list with one joined sql? Also how would I use that with Will_Paginate plugin? Thank you

    Read the article

  • adding custom fields dynamically to a model

    - by pankajbhageria
    I have a model called List which has many records: class List has_many :records end class Record end The table Record has 2 permanent fields: name, email. Besides these 2 fields, for each List a Record can have 'n' custom fields. For example: for list1 I add address(text), dob(date) as custom fields. Then while adding records to list one, each record can have values for address and dob. Is there any ActiveRecord plugin which provides this type of functionality? Or else could you share your thoughts on how to model this? Thanks in advance, Pankaj

    Read the article

  • asp.mvc model design

    - by Radu D
    Hi, I am pretty new to MVC and I am looking for a way to design my models. I have the MVC web site project and another class library that takes care of data access and constructing the business objects. If I have in that assembly a class named Project that is a business object and I need to display all projects in a view ... should I make another model class Project? In this case the classes will be identical. Do I gain something from doing a new model class? I don't like having in views references to objects from another dll ... but i don't like duplicating the code neither. Did you encounter the same problem?

    Read the article

  • How to perform add/update of a model object that contains EntitySet

    - by David Liddle
    I have a similar concept to the SO questions/tags scenario however am trying to decide the best way of implementation. Tables Questions, QuestionTags and Tags Questions QuestionTags Tags --------- ------------ ---- QID QID TID QName TID TName When adding/updating a question I have 2 textboxes. The important part is a single textbox that allows users to enter in multiple Tags separated by spaces. I am using Linq2Sql so the Questions model has an EntitySet of QuestionTags with then link to Tags. My question is regarding the adding/updating of Questions (part 1), and also how to best show QuestionTags for a Question (part 2). Part 1 Before performing an add/update, my service layer needs to deal with 3 scenarios before passing to their respective repositories. Insert Tags that do not already exist Insert/Update Question Insert QuestionTags - when updating need to remove existing QuestionTags Here is my code below however started to get into a bit of a muddle. I've created extension methods on my repositories to get Tags WithNames etc. public void Add(Question q, string tags) { var tagList = tags.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList(); using (DB.TransactionScope ts = new DB.TransactionScope()) { var existingTags = TagsRepository.Get() .WithName(tagList) .ToList(); var newTags = (from t in tagList select new Tag { TName = t }).Except(existingTags, new TagsComparer()).ToList(); TagsRepository.Add(newTags); //need to insert QuestionTags QuestionsRepository.Add(q); ts.Complete(); } } Part 2 My second question is, when displaying a list of Questions how is it best to show their QuestionTags? For example, I have an Index view that shows a list of Questions in a table. One of the columns shows an image and when the user hovers over it shows the list of Tags. My current implementation is to create a custom ViewModel and show a List of QuestionIndexViewModel in the View. QuestionIndexViewModel { Question Question { get; set; } string Tags { get; set; } } However, this seems a bit clumsy and quite a few DB calls. public ViewResult Index() { var model= new List<QuestionIndexViewModel>(); //make a call to get a list of questions //foreach question make a call to get their QuestionTags, //to be able to get their Tag names and then join them //to form a single string. return View(model); } Also, just for test purposes using SQL Profiler, I decided to iterate through the QuestionTags entity set of a Question in my ViewModel however nothing was picked up in Profiler? What would be the reason for this?

    Read the article

  • ActionLink sending a model of a complex type

    - by Xenph Yan
    I'm trying to paginate the results of a "advanced search", I have a complex model that represents the search options; int ZipCode int MinAge int MaxAge Availability bool Monday bool Tuesday ... bool Friday Requirements bool FirstAid bool DriversLicense I'm using; <%: Html.ActionLink("Next »", "Save", "Notification", Model.options)%> Which correctly sends all the data at the first level, but anything that is a sub-object (Availability or requirements) isn't expanded in the URL, all I get is the class name and so I lose most of the search options when I click the link to change to a different page. Any thoughts?

    Read the article

  • Query for model by key

    - by Jason Hall
    What I'm trying to do is query the datastore for a model where the key is not the key of an object I already have. Here's some code: class User(db.Model): partner = db.SelfReferenceProperty() def text_message(self, msg): user = User.get_or_insert(msg.sender) if not user.partner: # user doesn't have a partner, find them one # BUG: this line returns 'user' himself... :( other = db.Query(User).filter('partner =', None).get() if other: # connect users else: # no one to connect to! The idea is to find another User who doesn't have a partner, that isn't the User we already know. I've tried filter('key !=, user.key()), filter('__key__ !=, user.key()) and a couple others, and nothing returns another User who doesn't have a partner. filter('foo !=, user.key()) also returns nothing, for the record.

    Read the article

  • verbose_name for a model's method

    - by mawimawi
    How can I set a verbose_name for a model's method, so that it might be displayed in the admin's change_view form? example: class Article(models.Model): title = models.CharField(max_length=64) created_date = models.DateTimeField(....) def created_weekday(self): return self.created_date.strftime("%A") in admin.py: class ArticleAdmin(admin.ModelAdmin): readonly_fields = ('created_weekday',) fields = ('title', 'created_weekday') Now the label for created_weekday is "Created Weekday", but I'd like it to have a different label which should be i18nable using ugettext_lazy as well. I've tried created_weekday.verbose_name=... after the method, but that did not show any result. Is there a decorator or something I can use, so I could make my own "verbose_name" / "label" / whateverthename is?

    Read the article

  • Cast/initialize submodels of a Backbone Model

    - by nambrot
    I think I have a pretty simple problem that is just pretty difficult to word and therefore hard to find a solution for. Setup: PathCollection is a Backbone.Collection of Paths Path is a Backbone.Model which contains NodeCollection (which is a Backbone.Collection) and EdgeCollection (which is a Backbone.Collection). When I fetch PathCollection paths = new PathCollection() paths.fetch() obviously, Paths get instantiated. However, I'm missing the spot where I can allow a Path to instantiate its submodels from the attribute hashes. I can't really use parse, right? Basically im looking for the entry point for a model when its instantiated and set with attributes. I feel like there must be some convention for it.

    Read the article

  • Using Property Builtin with GAE Datastore's Model

    - by ejel
    I want to make attributes of GAE Model properties. The reason is for cases like to turn the value into uppercase before storing it. For a plain Python class, I would do something like: Foo(db.Model): def get_attr(self): return self.something def set_attr(self, value): self.something = value.upper() if value != None else None attr = property(get_attr, set_attr) However, GAE Datastore have their own concept of Property class, I looked into the documentation and it seems that I could override get_value_for_datastore(model_instance) to achieve my goal. Nevertheless, I don't know what model_instance is and how to extract the corresponding field from it. Is overriding GAE Property classes the right way to provides getter/setter-like functionality? If so, how to do it? Added: One potential issue of overriding get_value_for_datastore that I think of is it might not get called before the object was put into datastore. Hence getting the attribute before storing the object would yield an incorrect value.

    Read the article

  • R: including model specifications in xtable(anova(...))

    - by HamiltonUlmer
    Hello R comrades: I have a bunch of loglinear models, which, for our purposes will just be glm() objects called mx, my, mz. I want to get a nicely-formatted xtable of the analysis of deviance, so naturally I would want to perform xtable(anova(mx, my, mz, test = "Chisq")). The vanilla output of xtable, however, doesn't include the model specifications. I'd like to include those for all the ANOVA tests I'm running, so if there is not a param I'm missing that does this I'll probably just have to hack up my own solution. But looking over the help page, there doesn't seem to be an easy way to include the model specifications. Any thoughts? Alternatives? If it helps this was done in 2.9.1 with xtable 1.5-5.

    Read the article

  • Cannot save model due to bad transaction? Django

    - by Kenneth Love
    Trying to save a model in Django admin and I keep getting the error: Transaction managed block ended with pending COMMIT/ROLLBACK I tried restarting both the Django (1.2) and PostgreSQL (8.4) processes but nothing changed. I added "autocommit": True to my database settings but that didn't change anything either. Everything that Google has turned up has either not been answered or the answer involved not having records in the users table, which I definitely have. The model does not have a custom save method and there are no pre/post save signals tied to it. Any ideas or anything else I can provide to make answering this easier?

    Read the article

  • Passing values from action class to model class in symfony

    - by THOmas
    I have a action class for saving some data to a database.In action class iam getting a id through url.I have to save the id in table. I am getting the id by $request-getParameter('id') I used this code for saving $this-form-bind($request-getParameter('question_answers')); if ($this-form-isValid()) { $this-form-save(); $this-redirect('@homepage'); } in model class i used a override save method to save extra field public function save(Doctrine_Connection $conn = null) { if ($this-isNew()) { $now=date('Y-m-d H:i:s', time()); $this->setPostedAt($now); } return parent::save($conn); so i want to get the id value here . So how can i pass id value from action class to model class is any-other way to save the id in action class itself Thanks in advance

    Read the article

  • How to model dependency injection in UML ?

    - by hjo1620
    I have a Contract class. The contract is valid 1 Jan 2010 - 31 Dec 2010. It can be in state Active or Passive, depending on which date I ask the instance for it's state. ex. if I ask 4 July 2010, it's in state Active, but if I ask 1 Jan 2011, it's in state Passive. Instances are created using constructor dependency injection, i.e. they are either Active or Passive already when created, null is not allowed as a parameter for the internal state member. One initial/created vertex is drawn in UML. I have two arrows, leading out from the initial vertex, one leading to state Active and the other to state Passive. Is this a correct representation of dependency injection in UML ? This is related to http://stackoverflow.com/questions/2779922/how-model-statemachine-when-state-is-dependent-on-a-function which initiated the question on how to model DI in general, in UML.

    Read the article

  • Get a queryset of objects through an intermediary model

    - by skyl
    I want get all of the Geom objects that are related to a certain content_object (see the function I'm trying to build at the bottom, get_geoms_for_obj() class Geom(models.Model): ... class GeomRelation(models.Model): ''' For tagging many objects to a Geom object and vice-versa''' geom = models.ForeignKey(Geom) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() def get_geoms_for_object(obj): ''' takes an object and gets the geoms that are related ''' ct = ContentType.objects.get_for_model(obj) id = obj.id grs = GeomRelation.objects.filter( content_type=ct, object_id=id ) # how with django orm magic can I build the queryset instead of list # like below to get all of the Geom objects for a given content_object geoms = [] for gr in grs: geoms.append(gr.geom) return set(geoms) # A set makes it so that I have no redundant entries but I want the # queryset ordering too .. need to make it a queryset for so many reasons...

    Read the article

  • Convert executed SQL result to a list of Model object

    - by huynq9
    I'm wondering that is it possible to convert the executed query result to a list of models. I'm using Ruby with ActiveRecord and need to execute custom SQL query to join two or many tables. The code looks like below: connection = ActiveRecord::Base.connection sql = "select T1.f1, T2.f2 from T1 left join T2 on T1.id = T2.id" @result = connection.execute(sql) In Ruby code, I defined a models to manage the executed SQL result: class Model property :f1, :f2 end Is there any way to convert @result to list of Model object? so I can deal with each item in the list as following @result.each do |item| puts item.f1 puts item.f2 end

    Read the article

  • asp.net mvc default model binding problem

    - by csetzkorn
    I have some problems with ASP.NET MVC’s default model binder. The View contains HTML like this: <input name="SubDTO[0].Id" value="1" type="checkbox"> <input name="SubDTO[1].Id" value="2" type="checkbox"> This is my simplified ‘model’: public class SubDTO { public virtual string Id { get; set; } } public class DTO { public List<SubDTO> SubDTOs { get; set; } public DTO() { SubDTOs = new List< SubDTO>(); } } All this works fine if the user selects at least the first checkbox (SubDTO[0].Id). The controller ‘receives’ a nicely initialised/bound DTO. However, if the first check box is not selected but only, for example, SubDTO[1].Id the object SubDTOs is null. Can someone please explain this ‘strange’ behaviour and how to overcome it? Thanks. Best wishes, Christian

    Read the article

  • Model Django Poll

    - by MacPython
    I followed the django tutorial here: http://docs.djangoproject.com/en/dev/intro/tutorial01/ and now I am at creating a poll. The code below works fine until I want to create choices, where for some reason I always get this error message: line 22, in unicode return self.question AttributeError: 'Choice' object has no attribute 'question' Unfortunatley, I dont understand where I made an error. Any help would be greatly appreciated. Thanks for the time! CODE: import datetime from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question def was_published_today(self): return self.pub_date.date() == datetime.date.today() class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField() def __unicode__(self): return self.question

    Read the article

  • Model state inferno - how can Model.A be two different things at the same time?

    - by Martin
    I have this <%=Model.StartDate%> <%=Html.Hidden("StartDate", Model.StartDate)%> it outputs: 2010-05-11 11:00:00 +01:00 <input type="hidden" value="2010-03-17 11:00:00 +01:00" name="StartDate" id="StartDate"> What the... It's a paging mechanism so the hidden value was valid on the first page and I've been able to move forward to the next page. But since the values won't update properly it ends there. What do I need to do? Using firefox.

    Read the article

  • ASP.NET MVC: View does not get rendered with updated model value

    - by Newton
    I'm experiencing the a challenge in populating the child records. My previous code was like - <%= Html.TextBox("DyeOrder.Summary[" + i + "].Ratio", Model.DyeOrder.Summary[i].Ratio.ToString("#0.00"), ratioProperties) %> This code does not render the updated values after post back. To resolve this issue my work around was like - <%= "<input id='DyeOrder_Summary_" + i + "__Ratio' name='DyeOrder.Summary[" + i + "].Ratio' value='" + Model.DyeOrder.Summary[i].Ratio.ToString("#0.00") + "' " + ratioCss + " type='text' />"%> This is very clumsy to me. Is there any better ideas...

    Read the article

< Previous Page | 51 52 53 54 55 56 57 58 59 60 61 62  | Next Page >