You probably should rethink your database design. You will surely do not 
wish to prohibit your sellers from buying things on your commerce site.

So leave your auth_user table alone and create three other tables, like so:

db.define_table('reseller_rating', Field('rating', 'integer'), 
Field('reseller', 'reference auth_user, requires=IS_IN_DB(db, 'auth_user.id 
....
db.define_table('distributor_rating', Field('rating', 'integer'), 
Field('distributor', 'reference  auth_user, requires=IS_IN_DB(db, 
'auth_user.id ....
db.define_table('buyer_rating', Field('rating', 'integer'), Field('buyer', 
'reference auth_user', requires = IS_IN_DB

Actually, unless you have a clear difference in mind between distributors 
and resellers, I think you can get rid of the  reseller table.

Then you create a controller called 'distributor_rating' with a function 
called 'add.'

If you want to compute the average rating in the controller, user 
SQLFORM.factory or SQLFORM.custom_form. You can read up on those on the 
on-line book in the "Forms and Validators" chapter.



On Monday, October 14, 2013 4:12:26 PM UTC-4, Apple Mason wrote:
>
> Suppose I have three different types of users: buyer, distributor, and 
> reseller.
>
> All buyers, distributors, and resellers have an email, password, and 
> ratings. Since email and password are already part of auth_user, the 
> ratings Field will be an extra field in auth_user.
>
> To separate the user roles, we can user auth_membership and auth_group to 
> designate an auth_user as a 'buyer', 'distributor', or 'reseller'. 
>
> Although each user role uses the same backend code for storing email and 
> password (through auth_user), how would one go about storing a custom 
> rating mechanism for each user role?
>
> For example, let's say:
>
> A buyer is rated with some combination of # of product reviews written and 
> credible purchase history.
>
> A reseller is rated with some combination of buyer reviews and warranty 
> service.
>
> A distributor is rated with reseller reviews.
>
> Assuming I have the following functions which returns on an integer with 
> range 1 - 100 for ratings:
>
> def buyer_calc_rating():  # Random calcluation for this example
>      comment_num = len(db(db.comments.user == db.buyer.id).select())
>      purchase_history = #... some calculation that returns int
>
>      return comment_num + purchase_history
>
> def reseller_calc_rating();   # Assume similar calculation returns int
> def distributor_calc_rating();  # Assume similar calculation returns int
>
> I have two questions:
>
> - How would I go about assigning these functions to user's ratings Field 
> in auth_user?
>
> - How would the ratings be dynamically updated each time something changes 
> pertaining to rating calculation (ie, when a buyer rates a seller, etc)?
>
>    Would the preferred way be to stick the above functions in a module 
> which is then called wherever some controller function changes ratings? I 
> would always get an update-to-date rating on the user this way (simply by 
> querying 'db.auth_user.rating'), but that would also be a code-maintanence 
> nightmare since I would have to keep track of all the places in the code 
> that manipulates ratings?
>
> Thanks in advance.
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to