Hi Leonardo. managed to make the implementation of the cart. not used the
card but django django carton. There are the same but they are similar.
veleu for help. I'm passing the objects by post. Thanks for the help.
Em 02/10/2013 04:10, "Leonardo Giordani" <giordani.leona...@gmail.com>
escreveu:

> Hi Ricardo,
>
> well this is a question that needs a good explanation. I try to give you
> some hints about what you need to research about:
>
> a. You need to send data to the Django server through a POST view. This is
> a HTTP "verb", that is one of many different ways the browser has to
> communicate with your server. In particular, POST views in Django work just
> like standard views (i.e. GET views), but the request object has a POST
> attribute which encompasses the data sent by the browser.
>
> b. To create a POST HTTP request in your browser you need to create a
> form, and Django can help you with a very very rich API.
>
> So the general roadmap to achieve what you want is:
>
> 1. Set up a POST view that processes the incoming data
> 2. Link the POST view to an URL
> 3. Create an HTML template which shows a form to the user and sends data
> back to the server.
>
> The 3rd point is obviously needed only if you have to show the user a form
> to collect the input he or she enters. You can also call POST views
> directly, e.g. including some JS that performs the request, but this is an
> advanced topic.
>
> Start by looking at this video 
> tutorial<http://www.youtube.com/watch?v=gQe_8Q4YUpg>and reading the docs on 
> Django
> Forms <https://docs.djangoproject.com/en/dev/topics/forms/>
>
> I'd suggest you to also check the following resources to understand the
> previous two matters:
>
> http://www.w3schools.com/tags/ref_httpmethods.asp
> https://docs.djangoproject.com/en/dev/ref/request-response/
> http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
> https://docs.djangoproject.com/en/dev/ref/forms/api/
>
> Feel free to ask more if you need help.
>
> Cheers,
>
> Leo
>
>
> Leonardo Giordani
> Author of The Digital Cat <http://lgiordani.github.com>
> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
> page <https://github.com/lgiordani> - My Coderwall 
> profile<https://coderwall.com/lgiordani>
>
>
> 2013/10/1 Ricardo Kamada <ricardokam...@gmail.com>
>
>> you already helped me a lot =)
>> Leonardo looks just http://dpaste.com/1402408/
>> On line 20 I pass a value of fixed amount in the template.
>> How would get the amount in input dynamically?
>>
>> Abs
>> [] s
>>
>> Ricardo
>>
>>
>> 2013/10/1 Leonardo Giordani <giordani.leona...@gmail.com>
>>
>>>  Ricardo,
>>>
>>> I think the example on the django-cart site are somehow incorrect: since
>>> you are going to change the database you shall use a POST view and not a
>>> GET.
>>>
>>> However, putting apart HTTP verbs for a moment, let's look at how you
>>> call views from URLs. If you write something like the following in your
>>> views.py (or whatever file you mapped in your urls.py)
>>>
>>>
>>> from django.conf.urls import patterns, url
>>>
>>> from django.shortcuts import render_to_response
>>>
>>> def my_view(request, product_id, quantity):
>>>     [do something with product_id and quantity]
>>>     return render_to_response('template.html')
>>>
>>> urlpatterns = patterns('',
>>>                        url(r'^(?P<product_id>\d+)/(?P<quantity>\d+)/$',
>>>                            my_view
>>>                        )
>>>
>>> you can browse to http://yoursite/path/1234/56 and have the Python
>>> function my_view(product_id=1234, quantity=56) called.
>>>
>>> Try and implement something like the above code and see if it works.
>>>
>>> As for the django_cart: when you modify the DB always use POST views and
>>> not GET, then you are right, you have to return a template rendering in
>>> your add_to_cart() view.
>>>
>>> Let me know if it comes to life =)
>>>
>>> Cheers,
>>> Leo
>>>
>>>
>>>
>>> Leonardo Giordani
>>> Author of The Digital Cat <http://lgiordani.github.com>
>>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>>> page <https://github.com/lgiordani> - My Coderwall 
>>> profile<https://coderwall.com/lgiordani>
>>>
>>>
>>> 2013/10/1 Ricardo Kamada <ricardokam...@gmail.com>
>>>
>>>>  Leonardo Hi thanks for the reply but I still can not understand.
>>>> I really need to pass the id and quantity parameters in the url? After
>>>> all I'm recording the items in the correct session?
>>>> I saw that the method has no return add_to_cart, as well as other
>>>> methods remove_from_cart.
>>>> In my template I am calling the method like this:
>>>> <div class="botao fr"> <a href="{% url "add_to_cart" 
>>>> detalhe_produto.id1%}"> Buy </ a> </ div>
>>>>
>>>> and URLs:
>>>> url (r '^ products / buy / $', 'cart.views.add_to_cart', name =
>>>> 'add_to_cart')
>>>>
>>>> You say that to pass arguments id and quantity that url?
>>>>
>>>> Ricardo
>>>>
>>>>
>>>> 2013/10/1 Leonardo Giordani <giordani.leona...@gmail.com>
>>>>
>>>>>  You have to implement an URL dispatcher that links an URL to your
>>>>> view.
>>>>> Read here <https://docs.djangoproject.com/en/dev/topics/http/urls/>and 
>>>>> feel free to ask again if something is still not clear.
>>>>>
>>>>> Leonardo Giordani
>>>>> Author of The Digital Cat <http://lgiordani.github.com>
>>>>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>>>>> page <https://github.com/lgiordani> - My Coderwall 
>>>>> profile<https://coderwall.com/lgiordani>
>>>>>
>>>>>
>>>>> 2013/10/1 Ricardo <ricardokam...@gmail.com>
>>>>>
>>>>>>  Hi, I have this same problem.
>>>>>> I'm looking for answer everywhere.
>>>>>> enemybass could implement?
>>>>>> If someone can help me with this
>>>>>>
>>>>>> [] s
>>>>>>
>>>>>> Em quarta-feira, 26 de setembro de 2012 05h33min24s UTC-3, enemybass
>>>>>> escreveu:
>>>>>>>
>>>>>>> https://github.com/bmentges/**django-cart<https://github.com/bmentges/django-cart>
>>>>>>>
>>>>>>> *I'm* a total *newbie* to *Django. *How to run method *add_to_car*t?
>>>>>>> In template I would have button "add to cart".
>>>>>>>
>>>>>>> Thanks.
>>>>>>>
>>>>>>> def add_to_cart(request, product_id, quantity):
>>>>>>>     product = Product.objects.get(id=product**_id)
>>>>>>>     cart = Cart(request)
>>>>>>>     cart.add(product, product.unit_price, quantity)
>>>>>>>
>>>>>>>
>>>>>>> My model look something like this:
>>>>>>>
>>>>>>> class Product(models.Model):
>>>>>>>     name = models.CharField(max_length=50**)
>>>>>>>     slug = models.SlugField()
>>>>>>>     unit_price = models.DecimalField(max_digits**=5, decimal_places=2)
>>>>>>>     category = models.ManyToManyField(Categor**y)
>>>>>>>
>>>>>>>     class Meta:
>>>>>>>         verbose_name = "Product"
>>>>>>>         verbose_name_plural = "Products"
>>>>>>>
>>>>>>>     def __unicode__(self):
>>>>>>>         return self.name
>>>>>>>
>>>>>>>  --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Django users" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to django-users+unsubscr...@googlegroups.com.
>>>>>>
>>>>>> To post to this group, send email to django-users@googlegroups.com.
>>>>>> Visit this group at http://groups.google.com/group/django-users.
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/django-users/cfabbfd6-01ac-4b40-b887-ea7d7cd59c06%40googlegroups.com
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>
>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to a topic in the
>>>>> Google Groups "Django users" group.
>>>>> To unsubscribe from this topic, visit
>>>>> https://groups.google.com/d/topic/django-users/M8zey6g_R6s/unsubscribe
>>>>> .
>>>>> To unsubscribe from this group and all its topics, send an email to
>>>>> django-users+unsubscr...@googlegroups.com.
>>>>>
>>>>> To post to this group, send email to django-users@googlegroups.com.
>>>>> Visit this group at http://groups.google.com/group/django-users.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/django-users/CAEhE%2BOkVVp1o5AvtHeDi6U5zsuTKr9swGiJshCh8XwcRfSE_tQ%40mail.gmail.com
>>>>> .
>>>>>
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to django-users@googlegroups.com.
>>>> Visit this group at http://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CAJTdXTFX650QKMe66rz4DRPeEe%3D6iDV2Re894rsuhf6Li82ixg%40mail.gmail.com
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/django-users/M8zey6g_R6s/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAEhE%2BOkmSBGSbO86OH%2BPc17W2r5PeLOEZdaaWspk8KNMt765mQ%40mail.gmail.com
>>> .
>>>
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAJTdXTFB39CfZ9dXiAMaVYuLenkTvXF8r7WL6u3kMrdkY%3DoXog%40mail.gmail.com
>> .
>>
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/M8zey6g_R6s/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAEhE%2BOmyRMEUpB_QMxchcqVC6JN3n1PLh%3D2bASEv_T64Fynrog%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJTdXTE3NEXWURE3P7MaXAzRvBAbzvNqH8rr7WeaG%3DicYr_PBg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to