A
A
arelay2015-08-13 14:41:28
Django
arelay, 2015-08-13 14:41:28

How to store the number of services?

How to organize the storage of the number of services.
There are two models:
Services (name, cost)
Orders/services performed (service, cost
)
from the phone, I apologize for the format)
And how to store the quantity?
How to organize the choice of this number?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Luxurious, 2015-08-13
@arelay

class Service(Model):
    name = ...
    price = ...

class Order(Model):
    service = ForeignKey(Service, related_name=u'orders')
    user =  ForeignKey(User, related_name=u'orders')
    done = BooleanField(default=False)

...
orders_by_user_and_service = some_service.orders.filter(user=some_user_instance, done=True)
# or
orders_by_user_and_service = some_user.orders.filter(service=some_service_instance, done=True)
# or
orders_by_user_and_service = Orders.objects.filter(user=some_user_instance, service=some_service_instance, done=True)
# or
orders_by_user_and_service = Orders.objects.filter(user_id=some_user_id, service_id=some_service_id, done=True)
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question