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 | |
parent | e36adb590425ee6fb15a03ef690b6a279c49250a (diff) |
posts: cleaned up model code and fixed template bug
Diffstat (limited to 'app/posts')
-rw-r--r-- | app/posts/models.py | 38 | ||||
-rw-r--r-- | app/posts/templates/posts/fieldnote_detail.html | 4 |
2 files changed, 6 insertions, 36 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) -""" diff --git a/app/posts/templates/posts/fieldnote_detail.html b/app/posts/templates/posts/fieldnote_detail.html index 3ebb7f8..a645e86 100644 --- a/app/posts/templates/posts/fieldnote_detail.html +++ b/app/posts/templates/posts/fieldnote_detail.html @@ -20,9 +20,9 @@ <header id="header" class="post-header"> <h1 class="p-name entry-title post-title" itemprop="headline">{{object.title|smartypants|safe}}</h1> {% if object.subtitle %}<h2 class="post-subtitle">{{object.subtitle|smartypants|safe}}</h2>{%endif%} - <div class="post-linewrapper"> + <div class="post-dateline"> {% if object.location %}<div class="p-location h-adr adr post-location" itemprop="contentLocation" itemscope itemtype="http://schema.org/Place"> - <h3 class="h-adr" itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">{% if object.location.country_name == "United States" %}<span class="p-locality locality" itemprop="addressLocality">{{object.location.name|smartypants|safe}}</span>, <a class="p-region region" href="/jrnl/united-states/" title="travel writing from the United States">{{object.location.state_name|safe}}</a>, <span class="p-country-name" itemprop="addressCountry">U.S.</span>{%else%}<span class="p-region" itemprop="addressRegion">{{object.location.name|smartypants|safe}}</span>, <a class="p-country-name country-name" href="/jrnl/{{object.location.country_slug}}/" title="travel writing from {{object.location.country_name}}"><span itemprop="addressCountry">{{object.location.country_name|safe}}</span></a>{%endif%}</h3> + <span class="h-adr" itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">{% if object.location.country_name == "United States" %}<span class="p-locality locality" itemprop="addressLocality">{{object.location.name|smartypants|safe}}</span>, <a class="p-region region" href="/jrnl/united-states/" title="travel writing from the United States">{{object.location.state_name|safe}}</a>, <span class="p-country-name" itemprop="addressCountry">U.S.</span>{%else%}<span class="p-region" itemprop="addressRegion">{{object.location.name|smartypants|safe}}</span>, <a class="p-country-name country-name" href="/jrnl/{{object.location.country_slug}}/" title="travel writing from {{object.location.country_name}}"><span itemprop="addressCountry">{{object.location.country_name|safe}}</span></a>{%endif%}</span> – <a href="" onclick="showMap({{object.latitude}}, {{object.longitude}}, { type:'point', lat:'{{object.latitude}}', lon:'{{object.longitude}}'}); return false;" title="see a map">Map</a> </div>{%endif%} <time class="dt-published published dt-updated post-date" datetime="{{object.pub_date|date:'c'}}" itemprop="datePublished">{{object.pub_date|date:"F"}} <span>{{object.pub_date|date:"j, Y"}}</span></time> |