Match two profiles in Django framework - python

I made a web app which consists of two categories(let's say A and B) of users and there is a common board upon which they can both post something. Now if a person(John) from category A is suggested that his best match is person(wick) from category B by a django card, how can I make something that notifies both of them.
Suppose JOHN like what WICK is offering and there is a book button he sees on WICK's card(mini profile). Now I want to notify Wick that JOHN is interested in you when JOHN clicks on the Book button.
example data
Manufacturer
M_ID From To M_Type T_Type T_Length T_Weight #Trucks
JOHN A B Boxes Open 12-Tyre 22 3
BLAKE C D Cylinders Trailer HIGH 23 2
GREG G H Scrap Open 14-Tyre 25 5
Transporter
T_ID From To T_Type T_Length T_Weight #Trucks Price
WICK A B Open 12-Tyre 22 5 1500
PATEL G H Open 14-Tyre 25 10 1200
NICK A B Open 12-Tyre 22 7 1900
The algo returns data in this format
Manufacturer Best Match Second Best
JOHN WICK NICK
GREG PATEL -
I can show JOHN that his best matches are WICK and NICK( and when he clicks on them their mini profile will be shown to him with a BOOK option but what do I do next to make something happen(alert WICK/NICK) when he clicks on the book button??

It's a rather broad question, but here goes.
JOHN clicks, and the processing of the request will either do something immediately (such as sending an e-mail to NICK), or it will store something in the database which will be brought to NICK's attention the next time NICK interacts with the application.
Perhaps a notifications table with foreign keys for JOHN (notifier), NICK (notifiee --yuk ), and associated data.
Something like this latter is how I will see at the top of the stackoverflow page, when you up-vote this post or add a comment. If I don't come back to stackoverflow for a month, I'll see it then, or you might include an expiry date with what you store so that after that period of time has passed, the notification will be considered stale and deleted on the fly without NICK ever becoming aware of it.
I expect you can find something that somebody else has written to implement most of this, somewhere out there. Probably, a form of middleware, if it is to be checked on literally every interaction rather than just at log-in. Sorry, I can't offer any pointers.

You shouldn't talk in SQL tables when in reality you work on Django ORM level of abstraction.
All you need is a ManyToMany field. You'll add that m2m field and show new ones to user offering was made for (maybe merge Manufacturer and Transporter to one Model (table) to not duplicate this functionality).
Instead of using auto m2m, I suggest you use through model to add extra field, such as Boolean has_been_seen. Or you can make a guess instance has been seen if user's last_activity is bigger than datetime that instance was created at.

Related

Can anyone help me out with discount coupons in Django?

Currently I am working on a E-Commerce Website, I Need to Implement these Offers on add to cart as the Products are being added, the Price should be discounted according to the Offer Provided.
The Offers are as follows:
Offer 1- Buy one get one free,
Offer 2- 50% off on more than 2000 buy,
Offer 3- 30% off on selecting more than 2 products to add to the cart.
I have made the E commerce website everything is fine but just don't know how to use the Offer logic and though tried multiple things but nothing worked as it should.
The offer must automatically work on cart as soon as the products are added and before payment gateway the discount should work and get deducted.
idk how are your models and what's exactly your problem but let's say price_all is a field in your cart model and count is how many products of one type are in cart.
for Offer 1 easily you can divide price(this is not price_all this field belongs to your product) into 2.or you can just double the count and I think the second way is better.
for Offer 2 you can add an if to check if price_all is more than 2000 or not.
for offer 3 you can check if the count is more than 2 or not easily.
you can check all of this in save() function of your model or you can make a presave signal for that.if you don't know how just read the docs.

mySQL - Web application only with private users

I am attempting to make a web app, where there is a login system and then once you have logged in you can add things to your personal list.
I'm new to mySQL and website creation, so I'm a little confused on how to do this.
I need a user database:
users
id username name email password
1 john123 john john#gmail.com password
2 jenna23 jenna jenna#gmail.com password3
But I also need a database the hold the data of the users.
John's data looks like this:
item-name type image
cat animal cat.jpg
cheeto food cheeto.jpg
But Jenna's data looks like:
item-name type image
dog animal dog.jpg
grapes food grapes.jpg
I don't plan on the users being able to share data with each other like a blog post type system at least at this point. Right now I just want users to be use this site as a way to store their personal items.
Should each user have their own table? Or should I just put all of their data in one database, but couldn't that mess up somehow?

How to count consecutive rows with same value for a column in a database using django?

My App consists of a notification module. If the notifications are consecutively arrived from a same user, I would like to show "n notifications from john doe".
eg:
5 notifications from john doe
2 notification from james
4 notofications from john doe
How would I count these consecutive rows with same value in a column using django orm?
Suppose You have a model Notifications and another model named User. Then you can group by user_id
q=Notifications.objects.filter(user__id=1).values('user__first_name', 'user_id').annotate(c=Count('user__id'))
Just as Shafikur's answer above but I suppose you will have something to denote that the notification is new or hasn't been read. So let's add one more piece to the filter:
q=Notification.objects.filter(user__id=1, status='new').values('user__first_name', 'user_id').annotate(c=Count('user__id'))
It's not certain how you track the new notifications in your model, so this is just a rough guess which you should be able to apply to your particular case

Record rules to restrict employee subordinate hierarchy view ODOO

I want to set some record rules to restrict employees to view only their profile and their subordinates profiles. No one else out of a particular employee's subordinate hierarchy should be displayed to him. For example, this is my employee hierarchy.
Group One:
Ned
Cat
sansa
arya
Group Two
Robert
cersi
jammi
jofery
When Ned logged in, he should see cat,sansa and arya employee record but not Robert record.
Likewise when robert logged in, he should see cersi, jammi, jofery employee record.
The relation is sansa is reporting to cat whereas Cat is reporting to Ned.
What I get is:
When I logged in as Ned, I can able to see the Cat record only
When I logged in as Cat, I can able to see the Sansa and arya records
But When I log in as ned, I want to see his subordinate as well cat subordinate records too.
Thanks in advance
There is one important operator is there for such kind of the condition exact like your requirement is : child_of
You need to manage your rules like below.
['|',('parent_id.user_id','child_of',[user.id]),('user_id','=',use‌​r.id)]
or
['|',('parent_id.user_id','child_of',[user.id]),('user_id','child_of',[use‌​r.id])]
I hope this will resolve your issue and fit in your requirement.

Getting names from facebook

I am having a baby soon and I want to give him a unique/relatively less known name from my country. I want to get all names on facebook for a given country (say India) and then find 1000 least common names. I am not able to determine if Facebook API allows me to do this. Can someone suggest which APIs I should look at?
If it is not possible in FB, is it possible in any other social network?
Thanks.
The Graph API. Although I think Graph API takes reference from a user and then search in his friends only or if he/she has a page then in their followers only. The users which are not connected to the user can not be accessed. I've never seen a function which can return all users or their userIDs.
Edit:-
Ok I've found that you might need the Open Graph API and the Action Types, but their's no Action type for country.
This isn't possible. The closest you can do is an FQL query on the name table
SELECT name FROM user WHERE contains('user763410baby')

Categories