I'm creating a project on mobile comparison and i'm using web-scraping for getting the mobile's data and directly rendering it on web-browser without creating any product's model for saving the data.
note: i have created User's model
i want to create add/remove favorite functionality. when user click on the heart icon, it should be added as favourite.
but i do not know how to do this without having model.
please help me to solve it.
thanks in advance.
Let say you have 3 tables like thsi:
**Product:**
id name price
1 'iphone' 36000
2 'redmi-6' 8000
**User:**
id username
1 'chirag'
2 'priyank'
**Favourite:**
id product_id user_id status
1 1 2 True
2 2 1 False
You just need to crate 2 tables product and favourite. The user table you can use that one provided by django. Import it like this:
from django.contrib.auth.models import User
Related
By default in opencart we have 2 product statuses (which we can use also in admin to filter products) - enabled and disabled.
I need to add a few more custom statuses, which will be just for my team which is working over the products (for example i want to add need description status, products with the custom statuses will not show in the front end (like disabled) so if the product is market with it, the team who is working on product descriptions will easy filter only the products that need descriptions).
I hope i explained clearly as well...Thank you...
If you look into the language file of product admin/language/language_name/catalog/product.php, there is $_['text_enabled'] and $_['text_disabled'], you can add $_['text_need_description'].
In category.php and product.php controllers you will find
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_disabled'] = $this->language->get('text_disabled');
Next to them, you can add
$data['text_need_description'] = $this->language->get('text_need_description');
You can check occurrences of 'enabled' and change accordingly. You also need to change the relevant templates and models.
In database, status is saved as 1 for enabled and 0 for disabled, you can save the value 2 for 'need description'.
When the products are fetched to be displayed to the customer on front-end, only the products with status 1 are fetched so you won't have to change that part.
I'm new to django and ORM in general, and so have trouble coming up with query which would join multiple tables.
I have 4 Models that need joining - Category, SubCategory, Product and Packaging, example values would be:
Category: 'male'
SubCategory: 'shoes'
Product: 'nikeXYZ'
Packaging: 'size_36: 1'
Each of the Model have FK to the model above (ie. SubCategory has field category etc).
My question is - how can I filter Product given a Category (e.g. male) and only show products which have Packaging attribute available set to True? Obviously I want to minimise the hits on my database (ideally do it with 1 SQL query).
I could do something along these lines:
available = Product.objects.filter(packaging__available=True)
subcategories = SubCategory.objects.filter(category_id=<id_of_male>)
products = available.filter(subcategory_id__in=subcategories)
but then that requires 2 hits on database at least (available, subcategories) I think. Is there a way to do it in one go?
try this:
lookup = {'packaging_available': True, 'subcategory__category_id__in': ['ids of males']}
product_objs = Product.objects.filter(**lookup)
Try to read:
this
You can query with _set, multi __ (to link models by FK) or create list ids
I think this should work but it's not tested:
Product.objects.filter(packaging__available=True,subcategories__category_id__in=[id_of_male])
it isn't tested but I think that subcategories should be plural (related_name), if you didn't set related_name, then subcategory__set instead od subcategories should work.
Probably subcategories__category_id__in=[id_of_male] can be switched to .._id=id_of_male.
I have an existing table called empname in my postgres database
(Projectid,empid,name,Location) as
(1,101,Raj,India),
(2,201,David,USA)
So in the app console it will have like the following
1)Projectid=Textbox
2)Ops =(view,insert,Edit)-Dropdown
Case1:
So if i write project id as 1 and select View Result:It will display all the records for Projectid =1(Here 1 record)
Case2:
If i write projectid as 3 and select insert it will ask for all the inputs like empid,name,address and based on that it will update the table .
Case3:
If i write projectid as 2 and select edit.Then it will show all the field for that id and user can edit any column and can save which will update the records in backend for the existing table
If there is not data found for the respective project id then it will display no records found
Please help me on this as I am stuck up with models
Once you have your models created, the next task should be the form models. I can identify atleast 3 form classes that you will need to create. One to display the information(case 1), another to collect information(case 2) and the last class to edit the information. Wire up the form to the views and add the urls.
A good reference could be a django a user registration form since it will have all the three cases taken care of.http://www.tangowithdjango.com/book17/chapters/login.html
I have an application with has different organisations and the user belongs to one organisation.The user creates files on that organisation and only to that organisation.
The problem arise when we try to display the "pk" attribute of the files created, if I create a file in organisation "A", I pause, somebody creates a record in the database in organisation "B" and I create a new file in organisation "A". The details would display like this.
Organisation A
Title pk
Record 1 1
Record 3 3
Organisation B
Title pk
Record 2 2
How can I make sure the id's are contiguos for every organisation, like this.
Organisation A
Title pk
Record 1 1
Record 2 2
Organisation B
Title pk
Record 1 1
i want to be able to record actions a logged in user does... persist / updates etc
i have set up discriminators etc and it works perfect however, it only records on all new persisted data...
so i have info on a table called user_actions,
1 - Added a new customer,
2 - Added a new memo
etc
however, it doesnt record any updates to entities on my db...
such as 1 - Updated user - id 1
...
i am thinking of dumping the discriminator superclass and use a the old way to record,,,... like create a table with the fields:
id | action type | description | user ID | date
im not sure, what is the best way to log all transactions in doctrine 2.1?
thanks
Have you consider of HasLifecycleCallbacks? You can track not only PostPersist but also PostUpdate and PostRemove(or even Pre*)