0

[ update about author ] Django Blog Python Learning v.2, bismillahirrahmanirrahim. Kali ini kita akan share update terbaru dari source code Django Blog Python Learning v.2 ini.

Yaitu Update About Author yang ada di setiap posts, bisa dilihat langsung dibawah posts ini. Lalu mana yang kita update?

1. Pada bagian blog/models.py ditambahkan 1 field baru berupa avatar, seperti dibawah ini:

class Author(models.Model):
    name = models.CharField(max_length=200)
    avatar = models.ImageField(upload_to='gallery', null=True, blank=True, help_text="Upload Image for Avatar")
    about = models.TextField(blank=True, null=True)
    email = models.EmailField(max_length=200, blank=True, null=True, unique=True)
    website = models.URLField(max_length=200, blank=True, null=True)

2. Menampilkan About Author di template posts.html. Untuk letaknya tepat dibawah {{ object.body|markdown }}.

<div class="panel panel-default">
 <div class="panel-heading">Author</div>
  <div class="panel-body">
    <div class="media">
      <div class="media-left media-middle" style="float:left;margin-right:10px;">
        <a href="{{ entry.author.website }}">
          <img class="media-object" alt="{{ entry.author.name }}" title="{{ entry.author }}" src="/media/{{ entry.author.avatar }}" style="width:64px;height:64px;">
        </a>
      </div>
      <div class="media-body">
        <h4 class="media-heading">{{ entry.author }}</h4>
        {{ entry.author.about }}<br />
          Website: <a href="{{ entry.author.website }}" target="_blank">{{ entry.author.website }}</a>
      </div>
    </div>
  </div>
</div>

Jika kurang jelas, bisa langsung kita lihat update’nya di github:

Update models.pyhttps://github.com/agusmakmun/Django-Blog-Python-Learning-v.2/commit/90a2263db14aa26645124ad0a561ee89b8567bc7

Update post.htmlhttps://github.com/agusmakmun/Django-Blog-Python-Learning-v.2/commit/b76b2812535da134e57708f0663bca5c43b3d0a7

python django

Your Answer

blog comments powered by Disqus