problem with django models- better design
I have a user table and sub_user table. Basically a User can have multiple sub_user.
class sub_user(models):
parent_userid = models.CharFie开发者_如何学Gold('parent userid', max_length = 128, blank=True, null=True)
Sub_User contain the parent_userid as char.
Now My problem is, A User can have only 1 cart but it can contain for different sub_user
How do I add it to my Cart table:
class Cart():
use = models.Fk(User, unique = True)
sub_user = models.ManyToMany(sub_user)
package = models.ManyToMany(Package)
amt = models.IntegetField()
Package is just a normal model.
My list is in this format =[ (sub_user, package), (sub_user,package), (sub_user, package)]
def add_to_cart( list):
#code for adding sub_user and package to cart table.
Basically I am trying to implement online shopping Cart. So user can select package and services for a particular sub_user. and amt is calculated from total package and service cost.
example:
user1, pack1, pack2, servi1,service 3, total_cost = 100, for sub_user = sub_user1
user1, pack1, pack10, servi1, total_cost = 10000, for sub_user = sub_user2
How can I implement the above table structure in my cart table. Is my cart table described above is correct.
Please help me out.
Thanks
精彩评论