Create django object using a view with no form

情到浓时终转凉″ 提交于 2019-12-04 15:03:47

You should get the id parameter using urls.py:

#urls.py
from appname.views import some_view

urlpatterns = patterns('',
    url(r'^schedule/addbid/(?P<id>\d+)$', some_view),
    ...
)

Take a look at the documentation about capturing parameters in the urlconf.

And then, in views.py you should construct a Bids Object using the id passed in the URL, the currently logged in user (request.user), and the biddschedule from your DB. For example:

#views.py
def some_view(request, id):
    if request.user.is_authenticated():
        # get the biddschedule from your DB
        # ...
        bids = models.Bids(id=id, owner=request.user, biddedschedule=biddedschedule)
        bids.save()
        return HttpResponse("OK")
    return Http404()

Catch the number via the urlconf. Get the current user via request.user. Create a model instance by calling its constructor, and save it to the database via its save() method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!