diff options
author | luxagraf <sng@luxagraf> | 2021-01-30 17:42:52 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf> | 2021-01-30 17:42:52 -0500 |
commit | 9d72bfd769b477a2cddc1f430ffded60d7c906cc (patch) | |
tree | b30e217775812fe91998628f9fe27959d0065813 /app/posts/models.py | |
parent | e36adb590425ee6fb15a03ef690b6a279c49250a (diff) |
posts: cleaned up model code and fixed template bug
Diffstat (limited to 'app/posts/models.py')
-rw-r--r-- | app/posts/models.py | 38 |
1 files changed, 4 insertions, 34 deletions
diff --git a/app/posts/models.py b/app/posts/models.py index 74376db..c6365f5 100644 --- a/app/posts/models.py +++ b/app/posts/models.py @@ -48,8 +48,7 @@ class PostType(models.IntegerChoices): class Post(models.Model): - old_id = models.IntegerField(blank=True, null=True) - site = models.ForeignKey(Site, on_delete=models.CASCADE) + site = models.ForeignKey(Site, on_delete=models.SET_NULL, default=1, null=True) title = models.CharField(max_length=200) short_title = models.CharField(max_length=200, blank=True, null=True) subtitle = models.CharField(max_length=200, blank=True) @@ -103,15 +102,11 @@ class Post(models.Model): return self.title def get_absolute_url(self): - if self.post_type == 0: - return reverse('guides:reviews:review-detail', kwargs={"slug": self.slug}) - if self.post_type == 1: - return reverse('guides:reviews:review-detail', kwargs={"slug": self.slug}) - if self.post_type == 2: + if self.post_type == PostType.ESSAY: return reverse('essays:detail', kwargs={"slug": self.slug}) - if self.post_type == 3: + if self.post_type == PostType.SRC: return reverse('src:detail', kwargs={"slug": self.slug}) - if self.post_type == 5: + if self.post_type == PostType.FIELD_NOTE: return reverse('fieldnote:detail', kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug}) if self.post_type == PostType.JRNL: return reverse('jrnl:detail', kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug}) @@ -263,28 +258,3 @@ class PostSitemap(Sitemap): def priority(self, obj): return obj.sitemap_priority - - -""" -for p in src: - s, created = Post.objects.get_or_create( - old_id=p.id, - title=p.title, - slug=p.slug, - body_markdown=p.body_markdown, - pub_date=p.pub_date, - enable_comments=p.enable_comments, - has_code=p.has_code, - status=p.status, - meta_description=p.meta_description, - post_type=3, - ) - print(p) - for t in p.topics.all(): - c,created = Category.objects.get_or_create( - slug=t.slug, - name=t.name, - pluralized_name=t.pluralized_name - ) - s.topics.add(c) -""" |