首页 > 其他 > 详细

Django入门与实践-第21章:迁移(完结)

时间:2018-09-05 14:35:35      阅读:139      评论:0      收藏:0      [点我收藏+]
python manage.py migrate

#boards/models.py
class Topic(models.Model):
    views = models.PositiveIntegerField(default=0) # <- here
    

python manage.py makemigrations
python manage.py migrate


#boards/views.py 

def topic_posts(request, pk, topic_pk):
    topic = get_object_or_404(Topic, board__pk=pk, pk=topic_pk)
    topic.views += 1
    topic.save()
    return render(request, ‘topic_posts.html‘, {‘topic‘: topic})

<!--templates/topics.html-->
{% for topic in topics %}
    <tr>
        <td><a href="{% url ‘topic_posts‘ board.pk topic.pk %}">{{ topic.subject }}</a></td>
        <td>{{ topic.starter.username }}</td>
        <td>{{ topic.replies }}</td>
        <td>{{ topic.views }}</td> <!-- here -->
        <td>{{ topic.last_updated }}</td>
    </tr>
{% endfor %}

 

Django入门与实践-第21章:迁移(完结)

原文:https://www.cnblogs.com/larken/p/9565148.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!