K
K
kAIST2019-04-11 14:22:15
Django
kAIST, 2019-04-11 14:22:15

How to implement list of services in django models?

There is a list of contractor services that you need to set to the administrator.
The contractor, when filling out his profile, must go through all of them and indicate which he provides and which he does not (along with additional attributes such as surcharge).
What is the best way to implement this in the context of models?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arseny Sokolov, 2019-04-12
@kAIST

Here is the simplest implementation of the model. Just when the performer adds services indicating additional. attributes, they will need to be entered and that's it. There is no need to block additional activity fields (only if the performer wants to temporarily disable services, and then return them back without losing the previously specified additional attributes).

from django.contrib.auth import get_user_model

Users = get_user_model()

class Services(models.Model):
  name = models.CharField(max_length=125)

class Pref(models.Model):
  service = models.ForeignKey("Service", on_delete=models.CASCADE)
  user = models.ForeignKey(Users, on_delete=models.CASCADE)
  price = models.DecimalField(max_digits=18, decimal_places=2)

D
Dimonchik, 2019-04-11
@dimonchik2013

how do you implement?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question