Ticket #7419: models.py

File models.py, 956 bytes (added by peschler, 16 years ago)

Models for the unittest demonstrating the issue.

Line 
1from django.db import models
2
3class Vocabulary(models.Model):
4 root = models.ForeignKey('Term', null=True, blank=True, related_name='root_of')
5
6 def save(self):
7 """When a vocabulary is saved and it has no root term, a new root
8 term is created. This happens only the first time a vocabulary is
9 saved.
10 """
11 super(Vocabulary, self).save()
12
13 if not self.root:
14 self.root = Term.objects.create(vocabulary=self)
15 super(Vocabulary, self).save()
16
17class Term(models.Model):
18 vocabulary = models.ForeignKey(Vocabulary)
19
20 def save(self):
21 super(Term, self).save()
22
23 # As soon as self.parent is referenced here, the unittest fails.
24 # It does not matter if the self.parent is printed, used or changed.
25 # Any of the following will make the unittest fail!
26 #print "term.vocabulary:", self.vocabulary
27 self.vocabulary
28
Back to Top