當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。