编写一个简单的问答网站,允许用户互相提问和回答问题。
我想对用户进行细分以授予他们权限,并且我假设最好的方法是创建组。(如果我错了,请告诉我。)想创建一个组并让每个注册的用户自动加入一个组。然后,该用户可以将数据提交到 CharField 并根据需要上传图像。
#models.py
class name(models.Model):
title = models.CharField(max_length = 500)
image = models.ImageField(upload_to = 'images')
pub_date = models.DateTimeField(auto_now_add = True)
author = models.ForeignKey(User)
现在假设用户已经注册并且当前登录,
#urls.py
urlpatterns = pattners(
url(r'^add/$', addQ)
#views.py
def addQ(request): #I know I'm probably missing something in the view)
return render_to_response("add.html")
#add.html
<h1>Add</h1>
<form action = "" method = "post">{% csrf_token %}
<label for = "AddQ"> Add: </label>
<input type = "text" name = "add" value = "" id = "add">
<label for = "image1"> Image: </label>
<input type = "image" name = "image1" value = "" id = "image1">
<input type = "submit" value = "Add" />
那么我需要做些什么来让用户向模型中添加问题呢?