Search Results

Search found 25123 results on 1005 pages for 'domain model'.

Page 116/1005 | < Previous Page | 112 113 114 115 116 117 118 119 120 121 122 123  | Next Page >

  • Django comparing model instances for equality

    - by orokusaki
    I understand that, with a singleton situation, you can perform such an operation as: spam == eggs and if spam and eggs are instances of the same class with all the same attribute values, it will return True. In a Django model, this is natural because two separate instances of a model won't ever be the same unless they have the same .pk value. The problem with this is that if a reference to an instance has attributes that have been updated by middleware somewhere along the way and it hasn't been saved, and you're trying to it to another variable holding a reference to an instance of the same model, it will return False of course because they have different values for some of the attributes. Obviously I don't need something like a singleton , but I'm wondering if there some official Djangonic (ha, a new word) method for checking this, or if I should simply check that the .pk value is the same with: spam.pk == eggs.pk I'm sorry if this was a huge waste of time, but it just seems like there might be a method for doing this, and something I'm missing that I'll regret down the road if I don't find it.

    Read the article

  • Django model manager didn't work with related object when I do aggregated query

    - by Satoru.Logic
    Hi, all. I'm having trouble doing an aggregation query on a many-to-many related field. Let's begin with my models: class SortedTagManager(models.Manager): use_for_related_fields = True def get_query_set(self): orig_query_set = super(SortedTagManager, self).get_query_set() # FIXME `used` is wrongly counted return orig_query_set.distinct().annotate( used=models.Count('users')).order_by('-used') class Tag(models.Model): content = models.CharField(max_length=32, unique=True) creator = models.ForeignKey(User, related_name='tags_i_created') users = models.ManyToManyField(User, through='TaggedNote', related_name='tags_i_used') objects_sorted_by_used = SortedTagManager() class TaggedNote(models.Model): """Association table of both (Tag , Note) and (Tag, User)""" note = models.ForeignKey(Note) # Note is what's tagged in my app tag = models.ForeignKey(Tag) tagged_by = models.ForeignKey(User) class Meta: unique_together = (('note', 'tag'),) However, the value of the aggregated field used is only correct when the model is queried directly: for t in Tag.objects.all(): print t.used # this works correctly for t in user.tags_i_used.all(): print t.used #prints n^2 when it should give n Would you please tell me what's wrong with it? Thanks in advance.

    Read the article

  • mvc2 validation problem (ambiguous reference between model and models)

    - by ile
    I followed instructions for mvc validation but I can't manage to solve this problem.... This is linq to sql model: I set Entity namespace to be CMS.Model If I try to declare partial class Article in Portal.Models namespace: public partial class Article { .... } Then, after using Article article somewhere in code I get following error: 'Article' is an ambiguous reference between 'Portal.Models.Article' and 'CMS.Model.Article' Portal is project name and CMS is area.... I followed these instructions I aslo created NerdDinner from scratch and in that example validation works. I can't figure out what am I doing wrong... someone noticed my mistake? Is it related with giving name to Entity namespace (in tutorial they used default one) Thanks in advance! PS I'd like to note that I'm c# newbie so I'm not really familiar with these partial classes

    Read the article

  • My presentation layer does not match my model layer even though I have no animations

    - by Kevin McCullough
    On iPhone I have a CALayer that I animate via Core Animation. Then at some point I change view controllers. I then return to the view controller with the CALayer and in viewWillAppear: I set the frame and position properties on my layer to move it back to its starting point. Setting these properties changes the model layer but the presentation layer still has the old values and its presentation layer does not update until the next animation I play. In the CA Programming guide it says "You can query an instance of CALayer for its corresponding presentation layer while an animation transaction is in process." Which, to me, implies that the presentation layer should only be different from the model layer during an animation. But there are no animations currently running. I even used kCATransactionDisableActions to ensure that when I set the position property an implicit animation is not started. Does anyone know why my presentation and model layers are out of sync? Thanks.

    Read the article

  • In a DDD approach, is this example modelled correctly?

    - by Tag
    Just created an acc on SO to ask this :) Assuming this simplified example: building a web application to manage projects... The application has the following requirements/rules. 1) Users should be able to create projects inserting the project name. 2) Project names cannot be empty. 3) Two projects can't have the same name. I'm using a 4-layered architecture (User Interface, Application, Domain, Infrastructure). On my Application Layer i have the following ProjectService.cs class: public class ProjectService { private IProjectRepository ProjectRepo { get; set; } public ProjectService(IProjectRepository projectRepo) { ProjectRepo = projectRepo; } public void CreateNewProject(string name) { IList<Project> projects = ProjectRepo.GetProjectsByName(name); if (projects.Count > 0) throw new Exception("Project name already exists."); Project project = new Project(name); ProjectRepo.InsertProject(project); } } On my Domain Layer, i have the Project.cs class and the IProjectRepository.cs interface: public class Project { public int ProjectID { get; private set; } public string Name { get; private set; } public Project(string name) { ValidateName(name); Name = name; } private void ValidateName(string name) { if (name == null || name.Equals(string.Empty)) { throw new Exception("Project name cannot be empty or null."); } } } public interface IProjectRepository { void InsertProject(Project project); IList<Project> GetProjectsByName(string projectName); } On my Infrastructure layer, i have the implementation of IProjectRepository which does the actual querying (the code is irrelevant). I don't like two things about this design: 1) I've read that the repository interfaces should be a part of the domain but the implementations should not. That makes no sense to me since i think the domain shouldn't call the repository methods (persistence ignorance), that should be a responsability of the services in the application layer. (Something tells me i'm terribly wrong.) 2) The process of creating a new project involves two validations (not null and not duplicate). In my design above, those two validations are scattered in two different places making it harder (imho) to see whats going on. So, my question is, from a DDD perspective, is this modelled correctly or would you do it in a different way?

    Read the article

  • Regex for url formatting (www.domain.tld to anchors)

    - by Kristaps
    Hi. I'm currently developing a little browser-based Twitter widget. Currently, I'm stuck with getting the URLs to work. I'm kinda newbie, when it comes to regex (I know, how to get parts of a string, but this one – tough one). So, I need a regex that would search/replace www.domain.tld -> <a href="http://www.domain.tld">http://www.domain.tld</a> With/without http://, preferably. Any advice is welcome. Thanks.

    Read the article

  • HowTo init Django model, before using it?

    - by mosg
    Hi. I'm new to python and django. Apps | Versions: Python 2.6.2 Django (working with PostgreSQL) Question: I wrote a simple model: class OperationType(models.Model): eid = models.IntegerField(unique=True) name = models.CharField(max_length=64) def __unicode__(self): tpl = 'eid="', str(self.eid), '" name="', self.name, '"' return ''.join(tpl) Now I need to initialize it, for example with this data: 0, "None" 1, "Add" 2, "Edit" 3, "Delete" But I need to initialize this data not with admin web panel, but after class model created in the same code. How to do this? Thanks for help!

    Read the article

  • Show different sub-sets of a view model's properties in an edit view

    - by Martin R-L
    In the context of C# 4, ASP.NET MVC 2, and NHibernate; I've got the following scenario: Let's assume an entity Product that have an association to ProductType. In a product edit view; how do I implement that only a sub-set of the product's properties are shown based on the ProductType association in an elegant and DRY way? I.e., different properties shall be shown for different values of a property of the ProductType. Use a product view model builder, and from different view models automagically generate the view with my own Html.EditorForModel() (including drop-downs and other stuff not out-of-the-box)? Attribute the properties of one view model and use the Html.EditorForModel() way aforementioned? Use one model, but implement different web controls (view strategies) (can it be done DRY?)? Something else entirely?

    Read the article

  • Import a Collada model doesn't align to pixels

    - by Dan Friedman
    Assume I have a model that is simply a cube. (It is more complicated than a cube, but for the purposes of this discussion, we will simplify.) So when I am in Sketchup, the cube is Xmm by Xmm by Xmm, where X is an integer. I then export the a Collada file and subsequently load that into threejs. Now if I look at the geometry bounding box, the values are floats, not integers. So now assume I am putting cubes next to each other with a small space in between say 1 pixel. Because screens can't draw half pixels, sometimes I see one pixel and sometimes I see two, which causes a lack of uniformity. I think I can resolve this satisfactorily if I can somehow get the imported model to have integer dimensions. I have full access to all parts of the model starting with Sketchup, so any point in the process is fair game. Is it possible? Thanks.

    Read the article

  • How do I find the "concrete class" of a django model baseclass

    - by Mr Shark
    I'm trying to find the actual class of a django-model object, when using model-inheritance. Some code to describe the problem: class Base(models.model): def basemethod(self): ... class Child_1(Base): pass class Child_2(Base): pass If I create various objects of the two Child classes and the create a queryset containing them all: Child_1().save() Child_2().save() (o1, o2) = Base.objects.all() I want to determine if the object is of type Child_1 or Child_2 in basemethod, I can get to the child object via o1.child_1 and o2.child_2 but that reconquers knowledge about the childclasses in the baseclass. I have come up with the following code: def concrete_instance(self): instance = None for subclass in self._meta.get_all_related_objects(): acc_name = subclass.get_accessor_name() try: instance = self.__getattribute__(acc_name) return instance except Exception, e: pass But it feels brittle and I'm not sure of what happens when if I inherit in more levels.

    Read the article

  • AJAX, Subdomains and the 200 OK response.

    - by b. e. hollenbeck
    A non-hypothetical but abstracted situation: I have a domain www.foo.com, from which I'm making an AJAX POST to beta.foo.com. Examining the XHR object, I see a response header of 200 OK, but no response text - I even get a response 12B long, which is the exact response (a 12-character string) that I'm expecting - but the response text is blank. If this is a cross-domain issue, why am I getting 200 OK, and better yet - why am I seeing the PHP functions fire on the beta.foo.com side - yet getting no response?

    Read the article

  • Setting up a SQL server outside the domain

    - by Ben
    Hi, im very new to this. I've set up an account "SQLBOX" thats on the a network, but not connected to the domain. I have installed an instance of SQL Server 2008 and am trying to connect to it from another machine on the network but am getting "Cannot connect to "SQLBOX"". From the "SQLBOX" i can connect to sqlservers on the domain, but not vice-versa. Any help would be greatly appreciated. Sorry if the description isn't great. EDIT I can ping the box from a machine on the domain

    Read the article

  • What's the topmost iframe in the same domain?

    - by Jakob Stoeck
    How can I get the topmost iframe which is in the same domain, i.e. iframe level 1 example.org iframe level 2 example.org iframe level 2 example.org iframe level 3 example.org <-- would give me iframe level 1 iframe level 1 other-example.org iframe level 2 example.org iframe level 2 example.org iframe level 3 example.org <-- would give me iframe level 2 iframe level 1 other-example.org iframe level 2 example.org iframe level 2 example.org <-- would give me iframe level 2 (this) I need it because I have a website which should work in an iframe of another domain and stand-alone. In this website there are scripts which depend on window.top which shouldn't be top but the topmost iframe in the same domain.

    Read the article

  • Map a domain to an MVC area

    - by Simon_Weaver
    Anybody got any experience in mapping a domain to an MVC area? Here's our situation: Old system (still active but will soon redirect to new store): www.example.com - our main site where we send traffic store.example.com - our store site which is a completely separate site that is indexed in google New system: www.example.com - same site as before www.example.com/store - new store site - built in an ASP.NET MVC area Because store is a separate domain google gives it a separate entry in the search results. I'd like to keep this benefit in future but wondering whether or not there is a good way to map a domain (store.example.com) to the MVC area or if its just going to be more trouble than its worth. PS. I'm not trying to keep existing indexing - its a completely separate store so thats not possible. I just want to redirect to the corresponding page in the new store. I'm just trying not to lose the benefit of two domains for SEO purposes.

    Read the article

  • Targeting specific material by name in the imported model

    - by Aleksander Lenart
    I'm trying to select a particular material in the imported model (via Collada loader) in Three.js. I know this can be done with the getChildByName method but it just doesn't work for me. I couldn't find any working example with this method included, either. What am I doing wrong here? loader = new THREE.ColladaLoader(); loader.load('myModel.dae', function ( collada ) { model = collada.scene; var myMaterial = model.getChildByName( 'materialName', true ); myMaterial.material = new THREE.MeshBasicMaterial( { wireframe: true } ); });

    Read the article

  • WPF - Handling events from user control in View Model

    - by Vitaly
    I’m building a WPF application using MVVM pattern (both are new technologies for me). I use user controls for simple bits of reusable functionality that doesn’t contain business logic, and MVVM pattern to build application logic. Suppose a view contains my user control that fires events, and I want to add an event handler to that event. That event handler should be in the view model of the view, because it contains business logic. The question is – view and the view model are connected only by binding; how do I connect an event handler using binding? Is it even possible (I suspect not)? If not – how should I handle events from a control in the view model? Maybe I should use commands or INotifyPropertyChanged?

    Read the article

  • How to handle model state errors in ajax-invoked controller action that returns a PartialView

    - by Robert Koritnik
    I have a POST controller action that returns a partial view. Everything seems really easy. but. I load it using $.ajax(), setting type as html. But when my model validation fails I thought I should just throw an error with model state errors. But my reply always returns 500 Server error. How can I report back model state errors without returning Json with whatever result. I would still like to return partial view that I can directly append to some HTML element. Edit I would also like to avoid returning error partial view. This would look like a success on the client. Having the client parse the result to see whether it's an actual success is prone to errors. Designers may change the partial view output and this alone would break the functionality. So I want to throw an exception, but with the correct error message returned to the ajax client.

    Read the article

  • translating specifications into query predicates

    - by Jeroen
    I'm trying to find a nice and elegant way to query database content based on DDD "specifications". In domain driven design, a specification is used to check if some object, also known as the candidate, is compliant to a (domain specific) requirement. For example, the specification 'IsTaskDone' goes like: class IsTaskDone extends Specification<Task> { boolean isSatisfiedBy(Task candidate) { return candidate.isDone(); } } The above specification can be used for many purposes, e.g. it can be used to validate if a task has been completed, or to filter all completed tasks from a collection. However, I want to re-use this, nice, domain related specification to query on the database. Of course, the easiest solution would be to retrieve all entities of our desired type from the database, and filter that list in-memory by looping and removing non-matching entities. But clearly that would not be optimal for performance, especially when the entity count in our db increases. Proposal So my idea is to create a 'ConversionManager' that translates my specification into a persistence technique specific criteria, think of the JPA predicate class. The services looks as follows: public interface JpaSpecificationConversionManager { <T> Predicate getPredicateFor(Specification<T> specification, Root<T> root, CriteriaQuery<?> cq, CriteriaBuilder cb); JpaSpecificationConversionManager registerConverter(JpaSpecificationConverter<?, ?> converter); } By using our manager, the users can register their own conversion logic, isolating the domain related specification from persistence specific logic. To minimize the configuration of our manager, I want to use annotations on my converter classes, allowing the manager to automatically register those converters. JPA repository implementations could then use my manager, via dependency injection, to offer a find by specification method. Providing a find by specification should drastically reduce the number of methods on our repository interface. In theory, this all sounds decent, but I feel like I'm missing something critical. What do you guys think of my proposal, does it comply to the DDD way of thinking? Or is there already a framework that does something identical to what I just described?

    Read the article

  • What simple methods are there to wrap a c++ based object model with a COM interface

    - by Rich
    I have a pre-existing c++ object model which represents the business layer tier of an application. I want to be able to expose the object model to applications written in other languages i.e vbscript, VB, javascript etc. I believe the best way of doing this is to wrap the business objects with a COM layer. What fast and effective methods are there for doing this. Any advice, links to practical "How to" documentation would be very much appreciated. Because I'm starting a bounty on this , here's a few extra guidelines for potential bounty hunters :- 1)I've decided on an ATL approach 2)I'm now specifically looking for links to really good "how to and quickly" documentation on wrapping a pre-existing c++ object model to make it useable by a scripting language like javascript 3) Something with small working examples showing me what code needs to be added to what files, e.g what goes into the cpp , idl and hpp/h etc. It' must include an example I can compile test and change to get a better understanding.

    Read the article

  • Django filter with two constraints on related model

    - by BJ Homer
    I have a django app with models as follows: A Question model An Answer model, with a ForeignKey back to the Question. (A question can have multiple answers.) A Flag model, with a ForeignKey to the Answer. (An answer can be flagged as inappropriate.) All of the above also have a user field, defining the user that created that object. I'm trying to get a list of all Questions with answers from the current user which have been flagged. I tried this: Question.objects.filter(answer__user=user).\ filter(answer__flag__isnull=True).distinct() … but I believe that will return a list of Questions with answers from the current user and with answers which have been flagged, but will not necessarily guarantee that it is the user's answer that has been flagged. Is there an easy way to do this? Basically, I want to make the answer part of the filter refer to the same answer on both of them. Please let me know if something is unclear.

    Read the article

  • View artifacts leaking into the model of MVC

    - by Jono
    In an ASP.NET MVC application (which has very little chance of having its view technology ported to something non-HTML, but whose functional requirements evolve weekly,) how much HTML should ideally be allowed to be directly represented in the Model? I might come across as a design bigot for this, but I regard it as bad practice to allow any view constructs to "leak" into the model in an MVC application (and vice versa). For example, a Model that represents an item you're about to purchase should know nothing about the HTML check box that says "add giftwrap/message", nor should it know about any HTML drop down lists for payment card types. Conversely the View shouldn't be doing work like figuring out button text by translating keys into values (by looking in resource files.)

    Read the article

  • How does Model binding with a selectlist work?

    - by rsteckly
    Hi, I'm having problems retrieving the values of a selectlist in my form collection. I've tried making a viewmodel with an attribute with the same name as the select list. I'm honestly just realizing I REALLY don't understand how model binding works with selectlists. I've just been assuming that the following conventions apply: Name the select list the same thing as the attribute on the model you want it to bind to. Apart from that, I really don't get it. I've looked at several books on it and they're useless frankly. How does a select list work with a) form collection and b) a particular model?

    Read the article

  • Implementing simple business model in Haskell

    - by elmes
    Supose we have a very simple model: Station has at least one Train Train has at least two Stations The model has to allow to check what stations any given train visits and to check what trains visit a particular station. How to model it in Haskell? I am a Haskell newbie, so please correct me: once an object is created, you cannot modify it - you can only make a new object based on that one (~immutability). Am I right? If so, I'll have to create a lot of temporary variables with semi-initialized objects (during deserialization or even in unit tests). Basically what I need is an example of modeling domain classes in Haskell - after reading "Learn you a haskell.." I still have no idea how to use this language.

    Read the article

  • Rails diff model config in dev or prod environment

    - by Denis
    Hi, I've a model which use paperclip, in dev env I want to store files on the file system. In production I want to store them on my s3 account. How to configure my model to reflet this difference? Here is my model class Photo < ActiveRecord::Base has_attached_file :photo, :styles => { :medium => "200x200>", :thumb => "100x100>" }, :storage => :s3, :s3_credentials => "#{Rails.root}/config/s3.yml", :path => "/:style/:filename" end

    Read the article

  • How can I support conditional validation of model properties

    - by Jeff
    I currently have a form that I am building that needs to support two different versions. Each version might use a different subset of form fields. I have to do this to support two different clients, but I don't want to have entirely different controller actions for both. So, I am trying to come up with a way to use a strongly typed model with validation attributes but have some of these attributes be conditional. Some approaches I can think of is similar to steve sanderson's partial validation approach. Where I would clear the model errors in a filter OnActionExecuting based on which version of the form was active. The other approach I was thinking of would to break the model up into pieces using something like class FormModel { public Form1 Form1Model {get; set;} public Form2 FormModel {get; set;} } and then we would validate appropriately depending on

    Read the article

< Previous Page | 112 113 114 115 116 117 118 119 120 121 122 123  | Next Page >