I want to have a relationship between two nodes, Artwork, and Art Price.
One content type creates pieces of art, and the other creates art prices for each artwork.
I used a nodereference in Art Price to create a relationship between artwork and art price. However, when a user tries to add an art price, there is a drop down select menu that will have the titles of all the pieces of art on the site (which will be a lot).
Is there anyway to have the two automatically connected, so that on an Artwork page, there could be a place for users to add prices of that specific artwork, without having the user having to manually select the title each time? In otherwords, could the two content types be automatically associated to each other, so it knows you are adding a price to that specific piece of art?
Comments
Is there anything more to an
Is there anything more to an Art Price than the price? If not you might want to use taxonomy or a CCK integer field with a select list.
Yes, I need multiple prices,
Yes, I need multiple prices, a date for the time it sold, and a reference from where it sold (ebay, private, auction, etc).
Personally, I'm wondering,
Personally, I'm wondering, why you are not putting the price tag directly on the Artwork (using currency CCK). If your problem is to make sure, that Artists don't make up their own prices, then there is always a way to limit acceptable prices to a list of predefined values...
or use the CCK field
or use the CCK field permissions option so that a role can't change that field?
I want users to add multiple
I want users to add multiple prices for each artwork. In other words, if a piece of art sold on ebay 3 times for $5,000, $4,500, and $6,000, then I want people to be able to add a price for each time it sells. I also want a cck for the date that it sold, and a cck for the place it sold (ebay, private, or auction).
This is why I can't have it part of the original artwork content type. Hopefully that makes it more clear.
Hopefully that makes it more
Hopefully that makes it more clear.
Actually not, since CCK files usually also support multiple values. I might guess however, that your problem goes something like this: An Artist creates a node of the Artwork type (which probably contains a preview and a description of a painting). Your website is then used to track, when and for how much money a copy of that Artwork was sold via a shopsystem. Each purchase produces a node of type Artprice (which probably contains the purchase price, date and reference to the Artwork - so it's actually a Receipt). Now you want both nodes to connect without having to edit the original Artwork node again.
That can be done using views and the back_links table. You could try the views definition, found here: http://www.onyxbits.de/content/revisiting-previously-covered-topic (it creates a sidebar block, but it could also easily be worked into providing a tab).
Hope that helps.
First, I observe your node
First, I observe your node reference may be backward. Art Work --> Art Price is One --> Many, right? Each art price should only be associated with one art work. The way you're doing it, a Art Price can be referenced by may different Art Works. Seems like the Art Price should be referencing the Art Work since each Art Price is only associated with one Art Work. Also, it does not make sense to have to edit the artwork just to add an art price to it.
Now, how would you show the prices in the Art Work nodes, since Art Work no longer contains CCK reference to the Art prices? You could use Views module and back references. Create a block display that takes a "node: nid" as an argument, gets the value of that argument from the currently displayed node("Provide default argument", "Node ID from URL"), and shows all the Art Price nodes referencing that argument. Then just add that block to your page.
A possible next step: Install prepopulate module. Then in your theming of your Art Work CCK node you can put in a link called "Add Sale" that uses this link
http://www.example.com/node/add/art_price?edit[art_work]=$node->nid
$node->nid should be available to your node template, but you'll have to figure out the right value to put in edit[---]. Prepopulate module will then fill in node reference to the art work based on the node you're viewing when you click the "Add Sale" link. If you want to get really fancy you could find a way to hide the node reference field in the art price node form, to prevent if from being changed, and simplifying the form.
You have hit the nail on the
You have hit the nail on the head. Thank you. I think everything you have said makes sense to me. I was able to get everything accomplished, except the views portion. I know the back references does work because the art prices page has a link back to the correct piece of art. However, the block I created does not show any values (even though they exist).
Is it possible that it is not able to get the "Node ID from URL" because I am using custom urls based on cck values (www.domain.com/artist/piece_of_art_title)?
I have the one argument setup like you suggested, and the Art price and Sales Date nodes. But how do these reference the correct argument?
Thank you so much. One more step closer to reaching my goals thanks to you.
Regarding "Node ID from URL",
Regarding "Node ID from URL", it works as long as the unalised path is of the form node/{nid}
I did just what I said as an
I did just what I said as an exercise. I have two node types: art_work, and art_sale. art_sale has a node reference on art_work, and an integer 'amount' field.
Here is my view:
http://i279.photobucket.com/albums/kk123/blogpost328/694198-1.png
The trick is to add a relationship: Content: Art Work (field_art_work), and then the argument ("node: nid") is on this relationship.
Those two steps are the magic to get all nodes that reference the current node
Adding the block to the left column look like this:
http://i279.photobucket.com/albums/kk123/blogpost328/694198-2.png
There are two art_sales nodes, both referencing "Mona Lisa". Note that they both show in the block.
I'll talk about "Add Sale" in the next post.
OK, now for the "New Sale"
OK, now for the "New Sale" link.
I never used the prepopulate module, but I though it would do what I needed and it did. I install it, then just put in this code into the "footer" section of the view:
[field_art_work][0][nid][nid] I got from the HTML of the node form:
node/add/art-sale is just the link to the node add form, using your node type with -'s instead of _'s. I click "New Sale", and what do you know? The node reference is already filled in! You could also add similar code to your node template.
It's funny, teaching this node reference stuff has made it crystal clear in my mind.
Hmmm... docs of prepopulate
Hmmm... docs of prepopulate seem a bit off. It only seemed to work.
This worked for me: edit[field_art_work][0][nid]
(only a single nid)
Playing around with this some
Playing around with this some more.... this will even cause redirect back to the art_work node after creating the new art_sale:
Ok, that's all. Good luck. I learned a few things myself.
You are seriously so awesome.
You are seriously so awesome. I missed the relationship part myself. I am working on following your steps right now and will report back when I have done everything.
Thank you. You saved me a lot of headache... Isn't it funny how sometimes teaching others sometimes helps yourself?
Hi, Is this method also
Hi, Is this method also usable for making users able to refer mistakes in the content of a node (weblinks node).
I have the usecase that I have weblinks nodes about campings, and want people to be able to give me response about mistakes or add-ons about the camping information places in the nodes.
Therefore I want to have a sort of contactform related to the node, so when I get the email, I can instantly see about what node the response is. May be something like prepopulating the "related" weblinks node? Is this possible using above method? How would I preceed otherwise?
Thanks a lot in advance for helping me!
greetings,
Martijn
from a novice - where put the nail
just a problem I tried to solve to enhance a job and job application (example from using drupal book chapt 3), but the problem is similar: add a link for users to apply for a job directly from the list of jobs (available postion), so users did not need to select it from a drop-down box from the application form.
my view list all job (avaiable position)
- I added a field in my view -
- i checked
Rewrite the output of this field- in text area i put :
<a href="../node/add/application? edit[title]=[title]"> submit application for [title] on %1 </a>- the text part of link was ok ( e.g. submit application for Registrar on Administration) but the link part of href is confusing the link and no replacement occurred.
The php code obviously is the best solution to avoid my problem. But I need some help to locate where
( where is in actual code your suggested footer function ) i can put your clever suggestion adapted to my need.
thanks in advance, Gianni
@sammyman you might want to
@sammyman you might want to look at this thread http://drupal.org/node/1160276