本文整理汇总了Python中books.models.Book.owner方法的典型用法代码示例。如果您正苦于以下问题:Python Book.owner方法的具体用法?Python Book.owner怎么用?Python Book.owner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类books.models.Book
的用法示例。
在下文中一共展示了Book.owner方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import owner [as 别名]
def add(request):
location = ''
if request.method == 'POST':
#print request
form = BookForm(request.POST)
bookids = request.POST.get('book_id','').strip().splitlines()
type = request.POST.get('id_type','')
for b in bookids:
q = {}
b = normalize(b,type)
if str(type.lower()) == 'upc':
q['ean'] = b
else:
q[str(type.lower())] = b
if list(Book.objects.filter(**q)):
request.user.message_set.create(message="Book %s already exists" % b)
else:
print "would add",type,b
book = lookup_book(b,type)
if book:
request.user.message_set.create(message="Added %s (%s)" % (b, book.title))
book.condition = request.POST.get('condition','').strip()
book.location = request.POST.get('location','').strip()
location = book.location
book.owner = User.objects.get(id=request.POST.get('owner','').strip())
book.save()
#book.update_offers()
form = BookForm(instance = book)
else:
request.user.message_set.create(message="%s not found" % b)
else:
b = Book()
b.condition = 'VERY_GOOD'
b.owner = User.objects.get(username = 'clarsen')
form = BookForm(instance=b)
#return HttpResponseRedirect(reverse('books.views.add'))
# return HttpResponseRedirect(reverse('books.views.index'))
return render_to_response('book_add.html', \
{ 'books' : [], \
'location': location, \
'form' : form }, \
context_instance=RequestContext(request))