I need a model that will be linked to a maximum of 3 data (of the same type).
Here is an example:
I have candidates that need to pass 3 steps to be recruited
class Candidate(models.Model):
user = models.ForeignKey(User)
step1 = models.TextField(blank=True, null=True,)
step2 = models.TextField(blank=True, null=True,)
step3 = models.TextField(blank=True, null=True,)
For each step there is a review by several persons
class Review(models.Model):
candidate = models.ForeignKey(Candidate)
reviewer = models.ForeignKey(User)
step1 = models.TextField(blank=True, null=True,)
step2 = models.TextField(blank=True, null=True,)
step3 = models.TextField(blank=True, null=True,)
- Should I factorize these objects which would give me 4 objects instead of 2
such asCandidate,Review,CandidateStepandReviewStep?- If yes, how can I limit to 3 steps ?
- If not, how can easily iterate through the steps ?
Example data:
obj, created = Candidate.objects.get_or_create(
user = SelectedCandidate
, defaults = {'step1': '', 'step2': '', 'step3': ''}
)
obj.step1 = 'I\'m really motivated'
obj.step2 = 'I\'m able to do this job'
obj.save()
obj, created = Review.objects.get_or_create(
user = request.user
, defaults = {'step1': '', 'step2': '', 'step3': ''}
)
obj.step1 = 'He seems over motivated'
obj.save()
What about three objects:
On view level. If you are going to use
ModelFromset, using max_num option.