Django入门与实践-第21章:迁移(完结)
Posted larken
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django入门与实践-第21章:迁移(完结)相关的知识,希望对你有一定的参考价值。
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章:迁移(完结)的主要内容,如果未能解决你的问题,请参考以下文章