当前位置: 首页>>代码示例>>Python>>正文


Python Photo.owner方法代码示例

本文整理汇总了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)
开发者ID:snooze6,项目名称:django-example,代码行数:28,代码来源:views.py

示例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)
开发者ID:daviddetena,项目名称:AGBO_Frikr_Django,代码行数:29,代码来源:views.py

示例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)
开发者ID:a-rodriguez296,项目名称:Django-Tutorial,代码行数:28,代码来源:views.py

示例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)
开发者ID:krainet,项目名称:Frikr,代码行数:27,代码来源:views.py

示例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)
开发者ID:lbarrous,项目名称:Frikr,代码行数:24,代码来源:views.py


注:本文中的photos.models.Photo.owner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。