In my content tree, I have a tree of content items which represent cities. For each of those I want to have logical connections to a set of... let's say... National Parks that are within 2 hours driving distance. So a city will have multiple parks... and each set will be different... but of course a park will also be associated with more than one city.
What kind of Item and field setup works well for this sort of situation? I will be creating a custom renderer for these items, so I'm mostly concerned with how this should look in Sitecore to maximize ease of use and performance.
I'm using Sitecore 6.2.
(cross-posting from SDN, please forgive me... but I want to encourage more Sitecore community here on StackOverflow)
For this kind of relationship you'll need the following structure:
Home
Cities
NY
London
Paris
Parks
Park1
Park2
Park3
The "City" template should have the Multilist type field called "Parks". The soulrce of this field should look to the root of Parks (Home > Parks). The same way the "Park" template has the Multilist field called "Cities". The source of this field should look to the root of Cities (Home > Cities).
In this way you'll be easily able to perform any kind of request.
Hope this helps.
If the connection has to be both ways one way you could handle it is by adding some code to the save event.
Let's assume we have a City template with a field called "Related Parks", and a Park template with a "Related Cities" field.
Say we save a City item with two parks in the "Related Parks" field. On the save event we could retrieve the two parks and insert the current city being saved into the "Related Cities" field on those parks.
I am not necessarily saying this is the best way to go about it, just another option.
Are you going to be doing any lookups from park to city? For instance, would you need to say "find all the cities that are associated with a given park"? Or will it just be "find all the parks that are associated with a given city"? If you need to do the lookups in both directions, things get a little trickier and I would probably recommend using a search index. However, if your lookup is only in one direction, you could just use a treelist field to make associations from one item to many others.
From your description I'm not entirely sure if you actually need to use that many-to-many relationship, or if a one-to-many path is all you need?
Related
We have a form in that we need two postcode and two city. I have created as entity reference field (Taxonomy). Created a taxonomy as with hierarchical order postcode as first level and cities mapped under postcode. I have totally 18k terms in single taxonomy. when i try to access the page i am getting Memory Limit error. In which i need to implement dependent dropdown. based on postcode selection cities need to be populated in city drop down field. Used Heirrchical select module. which is not suppported for large taxonomy. Any help.
You can do it by creating AJAX callback functions on form
In my model Person can have more than one partner, so the ManyToMany Model is the only answer (this has to be ManyToMany for other reasons, so please don't think about changing it).
If I use default widget i got a list of all persons with selected one, two maybe three persons (which are partners of Person).
It would be ok, if the Person list is about 10-100 - and it works on test database. But my prod database has 10.000 persons or more, so the ModelMultipleChoice widget would be filled with 10.000 records, and finding the correct partner will last ages, and memory usage isn't trivial.
I need only to see names of partners with possibility to unset it from person, and some possibility to add new just typing name. The best solution is to show listbox with filtered names after typing three or four first letters, but any solution would be great.
With forms it would be easier, but I need it in admin, so I'd like to use django admin standards.
Well, this might be a bit odd, but I was wondering if it is possible to make a search based on the label for choiceFields rather than the stored database value.
I have an app that when the user searches for a vehicle of type truck, the query can't retrieve results because the value stored in the database is tru, although choiceField label is truck. The same goes for gender female is fem, for example.
I could go around this problem with alternative ways, but I was wondering if Django had this implemented somehow.
I think you should consider changing the search functionality to search with the shortened name. You can still display the label on the front-end: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#Examples
Scenario
A well-known taco establishment wants to build a Django app with models Combo, ComboItem, Ingredient, and Order.
Headquarters wants to create various combos with included items and layout the original item ingredients and price.
Each franchise can then select which combos they will sell on their menu and is allowed to adjust the price and ingredients of combo items for their store.
When an order comes in, the combo and item details should show on a log and should not change in the future if HQ renames a combo or the franchise changes the price/ingredients.
Use Case
HQ creates the "Hot Taco Combo". It has three related combo items
a taco (price: $.99, ingredients: shell, beef, cheese, hot sauce)
churro-spirals (price: $.79)
drink (price: $1.29)
The NY franchise adds the Hot Taco Combo to their menu. They adjust the price of the taco to $1.49 and add lettuce to the taco.
A customer orders the combo with no cheese on the taco.
HQ changes the name of the combo to Fiery Taco Combo - NY's combo name updates but the taco remains the same custom price and still includes lettuce.
A manager at the NY franchise views all orders and see's one order for Hot Taco Combo and the taco ingredients are only shell, meat, and lettuce.
Issue
I'm struggling to decide the best way to handle this because a Combo is basically the same object at all three levels, but its related ComboItem objects can be different. HQ should be able to update Combo attributes like the name and it would update all franchise combo names, but the combo item customizations should remain. Additionally, combo details and customizations at the point of sale should never change once recorded, for accurate order records.
Originally I thought to have an AbstractBaseClass for each of the related models and objects that inherit from them at each business level, but that structure feels redundant and difficult to maintain.
Then I thought to use GenericForeignKey to relate the Combo to either HQ, Franchise, or an Order and duplicate objects where necessary as they move down the levels. This feels weird and error prone.
Has anyone dealt with a case like this or have any recommendations? Is it just a matter of being a complex problem and needing a complex solution or is there a simple approach I'm missing? Thank you in advance.
It sounds like rather than abstract base classes, you're looking to use multi-table inheritance: https://docs.djangoproject.com/en/1.8/topics/db/models/#multi-table-inheritance
I'd recommend reading through this whole section of the docs to see what your options are for inheritance styles: https://docs.djangoproject.com/en/1.8/topics/db/models/#model-inheritance
Given the following content tree, how could I associate Dealerships with Cars so that I can get a URL like this?
http://website/Dealerships/JimWhite/Ford
I need to be able to have the content viewable and editable under cars, but automatically updated under the dealerships.
I assume there is some kind of link I can do?
Home
Cars
Ford
Honda
Toyota
Dealerships
JimWhite
TomJones
Take a look at this document on SDN, especially the chapter about Sharing and Reusing Items and Field Values (Aliases, Proxies, Wildcard items).
I think you should look into aliases on the SDN.
My Item Mirror module might do the trick.
http://blog.capaxsolutions.co.uk/2010/06/09/sitecore-item-mirroring-making-an-item-appear-in-more-than-one-place/