diff options
author | CruiseDevice | 2020-09-05 16:31:29 +0530 |
---|---|---|
committer | ankitjavalkar | 2020-10-08 10:38:06 +0530 |
commit | e4a9897685b4958efb0d5bd86f57dc1584449619 (patch) | |
tree | 8cbda921879e957070f0023f1960bdb573210d2d /yaksh/models.py | |
parent | f61351f6a4e7a6150e66ca39f23ac14f9a60de96 (diff) | |
download | online_test-e4a9897685b4958efb0d5bd86f57dc1584449619.tar.gz online_test-e4a9897685b4958efb0d5bd86f57dc1584449619.tar.bz2 online_test-e4a9897685b4958efb0d5bd86f57dc1584449619.zip |
Make Post model generic.
- Fix breaking links in forum after change in models.
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index b172e79..c6d6f7b 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -42,6 +42,7 @@ from django.template import Context, Template from django.conf import settings from django.forms.models import model_to_dict from django.db.models import Count + # Local Imports from yaksh.code_server import ( submit, get_result as get_result_from_code_server @@ -309,6 +310,9 @@ class Lesson(models.Model): help_text="Youtube id, vimeo id, others" ) + post = GenericRelation('Post', related_query_name='lessons') + + def __str__(self): return "{0}".format(self.name) @@ -919,6 +923,7 @@ class Course(models.Model): view_grade = models.BooleanField(default=False) learning_module = models.ManyToManyField(LearningModule, related_name='learning_module') + post = GenericRelation('Post', related_query_name='courses') # The start date of the course enrollment. start_enroll_time = models.DateTimeField( @@ -2753,8 +2758,15 @@ class ForumBase(models.Model): class Post(ForumBase): title = models.CharField(max_length=200) - course = models.ForeignKey(Course, - on_delete=models.CASCADE, related_name='post') + target_ct = models.ForeignKey(ContentType, + blank=True, + null=True, + related_name='target_obj', + on_delete=models.CASCADE) + target_id = models.PositiveIntegerField(null=True, + blank=True, + db_index=True) + target = GenericForeignKey('target_ct', 'target_id') def __str__(self): return self.title |