Search Results

Search found 13838 results on 554 pages for 'disconnected model'.

Page 48/554 | < Previous Page | 44 45 46 47 48 49 50 51 52 53 54 55  | Next Page >

  • Rails routing/polymorphism issue - how to model the following

    - by 46and2
    Hi all, I have an app where a 'user' belong to a 'client' or a 'vendor' (and client and vendor has_many users). In the admin namespace, I want to administer these users - so an admin would choose a client or a vendor, then nav to that client's or vendor's users. My question is, short of making the user model polymorphic, how could I model/route this? Here is what I have in terms of routing: map.namespace :admin do |admin| admin.resources :clients admin.resources :vendors end I know I could do something like: map.namespace :admin do |admin| admin.resources :clients do |client| client.resources :users admin.resources :vendors do |vendor| vendor.resources :users end end But the above would definitely need me to treat the User as polymorphic. I'm just wondering what you would recommend or what my options are. Thanks.

    Read the article

  • How to update the filename of a Django's FileField instance ?

    - by pierre-guillaume-degans
    Hello, Here a simple django model: class SomeModel(models.Model): title = models.CharField(max_length=100) video = models.FileField(upload_to='video') I would like to save any instance so that the video's file name would be a valid file name of the title. For example, in the admin interface, I load a new instance with title "Lorem ipsum" and a video called "video.avi". The copy of the file on the server should be "Lorem Ipsum.avi" (or "Lorem_Ipsum.avi"). Thank you :)

    Read the article

  • PHP Fatal error, trying to request method inside model multiple times

    - by Tom
    The error message [23-Mar-2010 08:36:16] PHP Fatal error: Cannot redeclare humanize() (previously declared in /Users/tmclssns/Sites/nadar/nadar/trunk/webapp/application/filer/models/Filer/Aggregate.php:133) in /Users/tmclssns/Sites/nadar/nadar/trunk/webapp/application/filer/models/Filer/Aggregate.php on line 133 I have a "Filer" model which contains several methods to generate graphs. Each method in there related to generating graphs has the suffix "Graph" in the method name. As we have some performance issues, I try to render the graphs in advance (using cron) instead of rendering them on each request. The code below is what I came up with: public function generategraphsAction() { $this->_helper->viewRenderer->setNoRender(); $config = Zend_Registry::get('config'); $id = $this->_getParam('filerid'); $filer = new Filer($id); $filer_methods = get_class_methods($filer); foreach ($filer_methods as $filer_method) { if (preg_match('/^(.*)Graph$/i', $filer_method, $matches)) { $path = $config->imaging_caching_dir . "/$id/{$matches[1]}.png"; $filer->$matches[0]($path); } } // var_dump(get_class_methods($filer)); die; } The result from the var_dump(), when uncommented, is: array 0 => string '__construct' (length=11) 1 => string 'find_by_name' (length=12) 2 => string 'getPartner' (length=10) 3 => string 'getSlots' (length=8) 4 => string 'getGroups' (length=9) 5 => string 'grouplist' (length=9) 6 => string 'getAggregates' (length=13) 7 => string 'getVolumes' (length=10) 8 => string 'getAggregateVolumes' (length=19) 9 => string 'getShelves' (length=10) 10 => string 'getAutoSupportHistory' (length=21) 11 => string 'getAutoSupportMail' (length=18) 12 => string 'getOrphans' (length=10) 13 => string 'getAll' (length=6) 14 => string 'getDiskRevOverview' (length=18) 15 => string 'getDiskTypeOverview' (length=19) 16 => string 'getDiskTypeSizeFunctionOverview' (length=31) 17 => string 'getLicenses' (length=11) 18 => string 'removeGroup' (length=11) 19 => string 'addGroup' (length=8) 20 => string 'hasGroup' (length=8) 21 => string 'aggdefaultGraph' (length=15) 22 => string 'aggbarGraph' (length=11) 23 => string 'voldefaultGraph' (length=15) 24 => string 'volbarGraph' (length=11) 25 => string 'replicationGraph' (length=16) 26 => string 'getReplicationData' (length=18) 27 => string 'humanize' (length=8) 28 => string 'getFiler' (length=8) 29 => string 'getOptions' (length=10) 30 => string 'getCifsInfo' (length=11) 31 => string 'getCifsStats' (length=12) 32 => string '__get' (length=5) 33 => string 'tr' (length=2) 34 => string 'trs' (length=3) 35 => string 'fieldList' (length=9) The generategraphsAction() method finds the 'Graph' methods correctly: array 0 => string 'aggdefaultGraph' (length=15) 1 => string 'aggdefault' (length=10) array 0 => string 'aggbarGraph' (length=11) 1 => string 'aggbar' (length=6) array 0 => string 'voldefaultGraph' (length=15) 1 => string 'voldefault' (length=10) array 0 => string 'volbarGraph' (length=11) 1 => string 'volbar' (length=6) array 0 => string 'replicationGraph' (length=16) 1 => string 'replication' (length=11) However when the first graph is generated, it generates the above listed PHP fatal error. Anyone can come up with a solution to this? I tried to pass by reference or switch a few things around (like re declare the Filer model, $current_filer = new Filer($id); and unset() it again after the request, but resulted in the same error) without much success. The referenced method "humanize" isn't used for anything I'm doing at the moment, but belongs to the Model because it's used in several other places. Of course, removing the method is not really an option right now, and the model contains several other methods as well so I assume if I just move the humanize method around, it will generate an error on the next one. For reference, the humanize() method: public function humanize ($kbytes, $unit = null) { // KiloByte, Megabyte, GigaByte, TeraByte, PetaByte, ExaByte, ZettaByte, YottaByte $units = array('KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); if (null !== $units) { $i = array_search(substr($unit, -2), $units); if (! $i) { $i = floor((strlen($kbytes) - 1) / 3); } } else { $i = floor((strlen($kbytes) - 1) / 3); } $newSize = round($kbytes / pow(1024, $i), 2); return $newSize . $units[$i]; } Thanks in advance for the help offered.

    Read the article

  • Add custom Model Binders for derived objects and their base

    - by mare
    My class diagram: BaseContentClass Page inherits BaseContentClass Tab inherits BaseContentClass ... If I do this ModelBinders.Binders.Add(typeof(BaseContentObject), new BaseContentObjectCommonPropertiesBinder()); then when in controller action parameter of type Tab appears, custom model binder is not fired. It gets fired if I do this: ModelBinders.Binders.Add(typeof(Tab), new BaseContentObjectCommonPropertiesBinder()); But I don't want to go writing "n" number of Add statements in my global.asax.cs to associate all the derived classes with my custom model binder, do I? I don't know if I have any other option.

    Read the article

  • Fetch main model and translations in one query with globalize2

    - by J. Pablo Fernández
    Is there a way to fetch the model and the translations in one query when using globalize2? For example, having a model called Language which have two fields, code and name of which the second is translatable I do the following: en = Language.find_by_code("en") and it runs this query: SELECT SQL_NO_CACHE * FROM `languages` WHERE (`languages`.`code` = 'en') LIMIT 1 and when I do: en.name it runs: SELECT SQL_NO_CACHE * FROM `language_translations` WHERE (`language_translations`.language_id = 123 AND (`language_translations`.`locale` IN ('en','root'))) and if I do it again it'll re-run the query. Is there a way to fetch all the translated data in the first query? I've tried: en = Language.find_by_code("en", :joins => "JOIN language_translations ON language_translations.language_id = languages.id") but it made no difference. UPDATE: this is being discussed as an issue in globalize2: http://github.com/joshmh/globalize2/issues/#issue/33

    Read the article

  • What VS Projecttype for Model and Database?

    - by Tim
    Hello folks, i've just started a new asp.net project which could increase fastly(a small erp-system for our company). So i thought it would be a good idea to split at least the model from the view/controller(the asp.net project). Because it could be that i need to access some classes and the database from a windows app in future, i dicided to put the Model into its own Project. What Visual Studio 2005 Professional Projecttype is most suitable for this requirement and why? SqlServerProject (DB is MS Sql Server 2005 EP) Class Library Web Service Application Database project no separate Project/other(keep in mind VS 2005 has no ASP.NET MVC-Project) Thanks

    Read the article

  • Perl script to print out cars model and car color

    - by Gary Liggons
    I am tying to create a perl script to printout car models and colors, and the data is below. I want to know if there is anyway to make the car model heading a field so that I can print it any time I want to? the data below is a csv file. the way I want the data to look on a report is below as well This is how the data looks* Chevy blue,1978,Washington brown,1989,Dallas black,2001,Queens white,2003,Manhattan Toyota red,2003,Bronx green,2004,Queens brown,2002,Brooklyn black,1999,Harlem ****This is how I am trying to get the data to look in a report**** Car Model:Toyota Color:Red Year:2002 City: Queens

    Read the article

  • acts_as_solr returns all rows in the database when using the model as search query

    - by chris Chan
    In our application we're using acts_as_solr for search. Everything seems to be running smoothly except for the fact that using the model name as the search query returns every single row in the table. For example, let's say we have a users table. We specify acts_as_solr in our model to search the fields first name, last name and handle acts_as_solr :fields = [:handle, :lname, :fname]. When you use "user" as the search term it returns every single user in the system, or every row in the database as a result. Has anyone else run into this?

    Read the article

  • Unobtrusive Client Validation without accepting model

    - by user1010609
    I have simple form like this which accepts only two values string action and editText.Is there a way to enable Unobtrusive Client Validation on this without Data Annotations? Or do I have to accept model and use Data Annotations? I just need it to make sure editText is atleast 5 chars long. @using (Ajax.BeginForm("Action", "Controller", null, new AjaxOptions { OnFailure = "error", UpdateTargetId = "Pcedit" + @Model.ID})) { <textarea rows="3" cols="2" name="editText" style="width:100%;"></textarea> <br /> <input type="submit" name="action" value="Save"/> <input type="submit" name="action" value="Cancel"/> }

    Read the article

  • Rails Cache Sweeper and Model Callback Firing

    - by Topher Fangio
    Hey guys, I have the following classes: class Vigil < ActiveRecord::Base after_update :do_something_cool private def do_something_cool # Sweet code here end end class NewsFeedObserver < ActionController::Caching::Sweeper observe Vigil def after_update # Create a news feed entry end end Everything works as expected. The after_update in the sweeper requires that the do_something_cool method in the model has finished before it can run properly. The problem is that the after_update in the sweeper is being called before (or perhaps at the same time as) the do_something_cool callback and it's causing problems. Does anyone know how to force the after_update in the sweeper to fire after the model callback? Is there better way to achieve this?

    Read the article

  • JavaFX - question regarding binding button's disabled state

    - by jamiebarrow
    I'm trying to create a dummy application that maintains a list of tasks. For now, all I'm trying to do is add to the list. I enter a task name in a text box, click on the add task button, and expect the list to be updated with the new item and the task name input to be cleared. I only want to be able to add tasks if the task name is not empty. The below code is my implementation, but I have a question regarding the binding. I'm binding the textbox's text variable to a string in my view model, and the button's disable variable to a boolean in my view model. I have a trigger to update the disabled state when the task name changes. When the binding of the task name happens the boolean is updated accordingly, but the button still appears disabled. But then when I mouse over the button, it becomes enabled. I believe this is due to JavaFX 1.3's binding being lazy - only updates the bound variable when it is read. Also, when I've added the task, I clear the task name in the model, but the textbox's text doesn't change - even though I'm using bind with inverse. Is there a way to make the textbox's text and the button's disabled state update automatically via the binding as I was expecting? Thanks, James AddTaskViewModel.fx: package jamiebarrow; import java.lang.System; public class AddTaskViewModel { function logChange(prop:String,oldValue,newValue):Void { println("{System.currentTimeMillis()} : {prop} [{oldValue}] to [{newValue}] "); } public var newTaskName: String on replace old { logChange("newTaskName",old,newTaskName); isAddTaskDisabled = (newTaskName == null or newTaskName.trim().length() == 0); }; public var isAddTaskDisabled: Boolean on replace old { logChange("isAddTaskDisabled",old,isAddTaskDisabled); }; public var taskItems = [] on replace old { logChange("taskItems",old,taskItems); }; public function addTask() { insert newTaskName into taskItems; newTaskName = ""; } } Main.fx: package jamiebarrow; import javafx.scene.control.Button; import javafx.scene.control.TextBox; import javafx.scene.control.ListView; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.scene.layout.HBox; def viewModel = AddTaskViewModel{}; var txtName: TextBox = TextBox { text: bind viewModel.newTaskName with inverse onKeyTyped: onKeyTyped }; function onKeyTyped(event): Void { txtName.commit(); // ensures model is updated cmdAddTask.disable = viewModel.isAddTaskDisabled;// the binding only occurs lazily, so this is needed } var cmdAddTask = Button { text: "Add" disable: bind viewModel.isAddTaskDisabled with inverse action: onAddTask }; function onAddTask(): Void { viewModel.addTask(); } var lstTasks = ListView { items: bind viewModel.taskItems with inverse }; Stage { scene: Scene { content: [ VBox { content: [ HBox { content: [ txtName, cmdAddTask ] }, lstTasks ] } ] } }

    Read the article

  • 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

  • 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

  • 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

  • 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

< Previous Page | 44 45 46 47 48 49 50 51 52 53 54 55  | Next Page >