本文整理汇总了Python中photos.models.Photo.owner方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.owner方法的具体用法?Python Photo.owner怎么用?Python Photo.owner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类photos.models.Photo
的用法示例。
在下文中一共展示了Photo.owner方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from photos.models import Photo [as 别名]
# 或者: from photos.models.Photo import owner [as 别名]
def post(self, request):
"""
Muestra un formulario
:param request:
:return:
"""
sucess_message = []
# Es esto seguro? -> Que pasa si meto owner con POST
photo_with_owner = Photo()
photo_with_owner.owner = request.user
form = PhotoForm(request.POST, instance=photo_with_owner)
if form.is_valid():
photo = form.save() # Guarda el objeto y me lo devuelve
sucess_message = 'Guardado con éxito '
sucess_message += '<a href=\"{0}\">'.format(reverse('photos_detail', args=[photo.pk]))
sucess_message += 'Ver foto'
sucess_message += '</a>'
form = PhotoForm()
context = {
'form': form,
'sucess_message': sucess_message
}
return render(request, 'photos/new_photo.html', context)
示例2: post
# 需要导入模块: from photos.models import Photo [as 别名]
# 或者: from photos.models.Photo import owner [as 别名]
def post(self, request):
"""
Crea una foto en base a la información POST
:param request: HttpRequest
:return: HttpResponse
"""
success_message = ''
photo_with_owner = Photo()
photo_with_owner.owner = request.user # asigno como propietario de la foto el usuario autenticado
form = PhotoForm(request.POST, instance=photo_with_owner)
if form.is_valid():
# Guarda el objeto del formulario en la DB y lo devuelve
new_photo = form.save()
# Inicializamos formulario, con el reverse componemos la url dinámica que mostrará con la nueva
# foto
form = PhotoForm()
success_message = 'Guardado con éxito!'
success_message += '<a href="{0}">'.format(reverse('photo_detail', args=[new_photo.pk]))
success_message += 'Ver foto'
success_message += '</a>'
context = {
# Pasamos en el context los datos que se mostrarán en el template
'form': form,
'success_message': success_message
}
return render(request, 'photos/new_photo.html', context)
示例3: post
# 需要导入模块: from photos.models import Photo [as 别名]
# 或者: from photos.models.Photo import owner [as 别名]
def post(self, request):
#Crea una instancia vacía de foto
photo_with_owner = Photo()
#Asigna los datos
photo_with_owner.owner = request.user
form = PhotoForm(request.POST, instance=photo_with_owner)
if form.is_valid():
new_photo = form.save() #Guarda el objeto que viene en el formulario y lo devuelve
#Poner todos los campos vacíos
form = PhotoForm()
success_message = 'Guardado con exito!'
#reverse sirve para generar la url
success_message += '<a href="{0}">'.format(reverse('photo_detail', args=[new_photo.pk]))
success_message += 'Ver Foto'
success_message += '</a>'
context = {
'form': form,
'success_message': success_message
}
return self.render(request, context)
示例4: post
# 需要导入模块: from photos.models import Photo [as 别名]
# 或者: from photos.models.Photo import owner [as 别名]
def post(self, req):
"""
Muestra un form para crear una foto y la crea si la peticion es POST
:param req: HttpRequest
:return: HttpResponse
"""
error_messages = []
success_message = ""
# Creamos owner y se lo pasamos al form con un objeto pre-establecido
photo_with_owner = Photo()
photo_with_owner.owner = req.user
form = PhotoForm(req.POST, instance=photo_with_owner)
if form.is_valid():
new_photo = form.save()
form = PhotoForm()
success_message = "Foto guardada con éxito! "
success_message += '<a href="{0}">'.format(reverse("photos_detail", args=[new_photo.pk]))
success_message += "(ver foto)</a>"
else:
error_messages.append("Formulario incompleto.")
context = {"form": form, "success_message": success_message}
return render(req, "photos/new_photo.html", context)
示例5: post
# 需要导入模块: from photos.models import Photo [as 别名]
# 或者: from photos.models.Photo import owner [as 别名]
def post(self, request):
"""
Crea la foto en base a la informacion del post
:param request: HttpRequest
:return: HttpResponse
"""
success_message = ''
photo_with_owner = Photo()
photo_with_owner.owner = request.user # Asigno como propietario de la foto al usuario autenticado actual
form = PhotoForm(request.POST, instance=photo_with_owner)
if form.is_valid():
new_photo = form.save() # Guarda el objeto y me lo devuelves
form = PhotoForm()
success_message = 'Foto guardada con exito!'
success_message += '<a href="{0}">'.format(reverse('photos_detail', args=[new_photo.pk]))
success_message += 'Ver foto'
success_message += '</a>'
context = {
'form': form,
'success_message': success_message
}
return render(request, 'photos/new_photo.html', context)