What's the best way to create models for this situation in django?
I'm creating a website about services provided by certain professionals.
Each professional creates his own personal page and lists services which
he provides, with prices.
However, he has a certain limited choice of service types to choose from.
The professional can't create new service types — it's admin's
prerogative. Each service that the professional lists has to be of a
certain pre-determined type, and he can't have to services of the same
type.
So far, that's what I have in models.py:
# Created and edited only by site administration
class Service(models.Model):
url_name = models.CharField(max_length=100, primary_key=True) # to use
in URLs
name = models.CharField(max_length=200)
description = models.TextField()
def __unicode__(self):
return self.name
class Master(models.Model):
name = models.CharField(max_length=200)
description = models.TextField()
def __unicode__(self):
return self.name
class MasterService(models.Model):
master = models.ForeignKey(Master)
service = models.ForeignKey(Service)
price = models.PositiveIntegerField(blank=True)
How can I edit that model in such a way that the django will "know" that
each master can only have 1 service of a certain Service type?
No comments:
Post a Comment