1.书籍的增删改查
1.ORM中第一外键
models.Foreignkey(to='要关联的表')
注意:ORM在数据库中会给外键字段自动加_id
2.查询
book_obj.publisher -->数据关联的出版社对象
book_obj.publisher_id -->数据关联的出版社id(数据库中真正保存的那一列的值)
3.添加
1.添加页面把所有的出版社数据展示成select标签
2.模态框添加,区别于跳转到新页面添加!
3.添加(注意参数)
Book.objects.create(title = new_title,publisher = Publisher.objects.get(id = publishers))
Book.objects.create(tite = new_title,publisher_id = publisher_idd)
4.编辑
1.模板语言:
for循环:
{% for bookname in Book_list%}
...
{% endfor%}
if条件
{% if publisher == book.publisher %}
<option selected value='{{publisher.id}}'>{{publisher.name}}</option>
{% esle %}
<option value="{{ publisher.id }}">{{ publisher.name }}</potion>
{% endif %}
2.注意.save()
obj.save()