Updating value in a html table django + bootstrap - django

I have a design with twitter bootstrap front-end and django backend, and I want to make on a shopcart a "plus/minus" button to update quantity and price. How would be the best option to do this?
Currently I am using a form with 2 buttons and updating the quantity and price values within the view. If I use Jscript how can I update the session fields quantiy and price ?
I want to achieve this : http://bootsnipp.com/snippets/featured/buttons-minus-and-plus-in-input but when clicking plus/minus to have price updated according to the quantity values.

Javascript can be used to update the price based on the quantity.
Django only does updates when you submit data to the database. You can make a shopping cart object in the database of coarse and save what the User has selected in that cart. But for updates on the page for the price and quantity without submitting data to the database it would be Javascript.
I recommend using Javascript on the page for price and quantity updates, and then when they select an "add-to-cart" button, then to submit the data like any other Django Form, and save the data in a shopping cart for that User's session.

I think for your situation a simple jquery function for when quantity element is changed will suffice.
for example something like
$(document).ready(function() {
$("#quantity").change(function(){
q = document.getElementById("quantity").val()
p = document.getElementById("price").val()
t = p*q
document.getElementById("total").val(t)
});
});

Related

Dsplay the coupon code in an opencart product page

Please help me to display the coupon code or coupon name in opencart 2.1.0.1 product page. For the promotion of products I need to display the coupons or promo code in the product page of opencart 2.1.0.1.
I think this will be hard coded, you will have to add a method to the copoun model which will take the product_id and return the copouns related to this product_id, then in the product controller you will need to call this method and list the copouns in a data variable, then in the product view you need to show them in the desired place.

Setting default value based on database in DJango

Good evening,
I am new to Django and am working on a sort of ticketing app. My app has three models, Ticket, Status, & Notes.
When displaying the ticket details, I have a form to add a Note. What I want to do is to add to the form a drop down that is set to the current status value of the ticket. When creating the form, how do I pass in the current status value to the form and use it as the default value?
Thanks.
You can set it when calling the form constructor in your view:
form = NoteForm(initial={'status': ticket.status})

Django ModelForm with Many to Many Field

I have a Django model for a List with a many to many field to Item, it uses a through table, that has a column for quantity.
I want to use Django forms to display a form such that the user can add items to the list. If I just try and create the ModelForm, it shows a selection box, where I can choose items, but there is no way to denote quantity for each item.
I'd like to have it display a dropdown menu where you can select an item, and an input box where you can enter the quantity.
Do I have to do something custom to get it to work this way?
EDIT: I could probably just write the form in HTML myself, but I want to use the validation features of Django forms in the backend too.
It sounds like what you want is an inline formset on the through table. That would give you the selection box for the item and the input box for the quantity.

How do I disable the update button on View Cart for specific product categories in OpenCart

I have an OpenCart site and would like to disable the update button in the View Cart page for products belonging to a specific category. If the products don't belong to the category, the update button will be enabled.
You can add a column in the database then add supporting code to the admin/controller, admin/template, catalog/controller, catalog/view/theme/yourtemplate. Then you can wrap the view cart button in your catalog/view/theme/yourtemplate/product/product.tpl with a PHP IF exists statement.
Just an example. Good luck!

Django how to edit data for multiple objects at once

I created two models in django. First is about products (name, price etc) and second is shop which contains this products.
How can I edit every product from my shop in one form?
For example i have page with shop detail (all products, prices) and I want on this page edit few prices of products from this shop. I don't want click on every product and edit it, I want do it on one page. Is it possible? What is the best way to do it?
You can use inline forms
# admin.py
class ProductInline(admin.StackedInline):
model = Product
class StoreAdmin(admin.ModelAdmin):
inlines = [ProductInline]
admin.site.register(Store, StoreAdmin)
With this configuration, you will be able to edit / add / delete related Products on the Store admin page.
Solution 1
The Django admin site, acessible at http://<myurl>:<myport>/admin/, will allow you do edit saved model data. Can't remember off the top of my head if you can edit multiples or not though..
Solution 2
Connect to your datasource using a SQL Editor for example, using MySQLWorkbench, and script it, which would allow you to update all the products for one shop in one fell swoop. Some example SQL would be update products set price='4.99' where shop_id=1 or something similar