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章:迁移(完结)的更多相关文章

  1. Django入门与实践-第26章:个性化工具(完结)

    http://127.0.0.1:8000/boards/1/topics/62/reply/ 我觉得只添加内置的个性化(humanize)包就会很不错. 它包含一组为数据添加“人性化(human t ...

  2. Django入门与实践-第14章:用户注册(完结)

    http://127.0.0.1:8000/signup/ django-admin startapp accounts INSTALLED_APPS = [ 'accounts', ] # mypr ...

  3. Django入门与实践-第13章:表单处理(完结)

    http://127.0.0.1:8000/boards/1/ http://127.0.0.1:8000/boards/2/ http://127.0.0.1:8000/boards/3/ http ...

  4. Django入门与实践-第12章:复用模板(完结)

    http://127.0.0.1:8000/http://127.0.0.1:8000/boards/1/http://127.0.0.1:8000/boards/2/http://127.0.0.1 ...

  5. Django入门与实践-第11章:URL 分发(完结)

    http://127.0.0.1:8000http://127.0.0.1:8000/boards/1/http://127.0.0.1:8000/boards/2/http://127.0.0.1: ...

  6. Django入门与实践-第25章:Markdown 支持(完结)

    http://127.0.0.1:8000/boards/1/topics/102/reply/ 让我们在文本区域添加 Markdown 支持来改善用户体验. 你会看到要实现这个功能非常简单. 首先, ...

  7. Django入门与实践-第24章:我的账户视图(完结)

    http://127.0.0.1:8000/settings/account/ #好的,那么,这部分将是我们最后的一个视图.之后,我们将专心来改进现有功能. #accounts/views.py fr ...

  8. Django入门与实践-第23章:分页实现(完结)

    http://127.0.0.1:8000/boards/1/ #从现在起,我们将在 board_topics 这个视图中来操作. python manage.py shell from django ...

  9. Django入门与实践-第22章:基于类的视图

    http://127.0.0.1:8000/boards/1/topics/2/posts/2/edit/ http://127.0.0.1:8000/ #boards/views.py from d ...

随机推荐

  1. oracle imp dmp

    windows>cmd> imp userid=用户名/密码@orcl file=d:\nc60.dmp full=y imp userid=SYSTEM/password@orcl fi ...

  2. Spring cron 定时调度配置

    IDEA 或者 STS http://spring.io/guides/gs/scheduling-tasks/ spring  mvc : 结构: Seconds Minutes Hours Day ...

  3. Java 阿里云 邮件(带附件)发送

    简单的使用. 阿里云每天免费200封 1000封才2块钱..465端口 使用正常25 端口 不正常 package com.gwzx.framework.utils; import java.util ...

  4. Linux tomcat启动慢, Creation of SecureRandom instance for session ID generation using [SHA1PRNG]took [xx] mil

    启动慢的解决链接:  http://blog.csdn.net/u011627980/article/details/54024974

  5. hibernate注解主键生成策略

    Id生成策略: @GeneratedValue,JPA通用策略生成器 . JPA提供的四种标准用法为TABLE,SEQUENCE,IDENTITY,AUTO.  TABLE:使用一个特定的数据库表格来 ...

  6. JavaScript eval_r() 函数

    定义和用法 eval_r() 函数可计算某个字符串,并执行其中的的 JavaScript 代码. 语法 eval_r(string) 参数 描述 string 必需.要计算的字符串,其中含有要计算的  ...

  7. ubuntu安装openssh-server 报依赖错误的解决过程

    ubuntu自带的有openssh-client,所以可以通过 ? 1 ssh username@host 来远程连接linux 可是要想通过ssh被连接,ubuntu系统需要有openssh-ser ...

  8. hive 抽样方法

    select * from (select *from advert.dws_advert_order_model_sample_pcvr_v2_diwhere dt>= date_sub('$ ...

  9. spark性能调优 数据倾斜 内存不足 oom解决办法

    [重要] Spark性能调优——扩展篇 : http://blog.csdn.net/zdy0_2004/article/details/51705043

  10. 在命令提示符下启动并使用JVM时,简单设置堆

    公司电脑内存太小了,只有8G:或者说JVM默认启动占用内存太大了,同时启动多个服务内存就炸了. 比如: java -Xmx128m -Xms64m -Xmn32m -Xss16m -jar eurek ...