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


Python Event.delete方法代码示例

本文整理汇总了Python中event.models.Event.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Event.delete方法的具体用法?Python Event.delete怎么用?Python Event.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在event.models.Event的用法示例。


在下文中一共展示了Event.delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: eventHandler

# 需要导入模块: from event.models import Event [as 别名]
# 或者: from event.models.Event import delete [as 别名]

#.........这里部分代码省略.........
                        events = Event.objects.select_related().prefetch_related().filter(qargs).order_by("on_date")[:limit]
                    elif filter == "popular":
                        events = Event.objects.select_related().prefetch_related().filter(qargs).order_by("-attends", "on_date")[:limit]
                    elif filter == "free":
                        qargs &= Q(price=0.0)
                        events = Event.objects.select_related().prefetch_related().filter(qargs).order_by("on_date")[:limit]
                except:
                    print traceback.format_exc()
                    
            stuff = serialize_events(events=events)
            return HttpResponse(stuff, mimetype="application/json")       
                    
        
        
        event_id = request.GET.get('event_id', None)
        if event_id is None:
            event_form = EventForm()
            artist_form = ArtistForm()
            venue_form = VenueForm()
            return render_to_response('add_event.html', locals(), context_instance=RequestContext(request))
        else:
            #event = Event.objects.get(pk=event_id)#.select_related().prefetch_related().filter(pk=event_id)[0]
            event = Event.objects.select_related().prefetch_related().get(pk=event_id)
            #print "lele", event, event.name
            #return render_to_response('poster_view.html', locals(), context_instance=RequestContext(request))
            stuff = serialize_events(events=[event])
            return HttpResponse(stuff, mimetype="application/json")     
            
    if request.method == 'POST':
        try:
            date = datetime.strptime(request.POST.get('date'), '%d-%m-%Y %H:%M')
            #date = datetime.strptime(request.POST.get('date'), '%d-%m-%Y')
            description = request.POST.get('description')
            price = request.POST.get('price')
            artist_ids = json.loads(request.POST.get('artist_ids'))
            venue_id = request.POST.get('venue_id')
            poster_id = request.POST.get('poster_id')
            
            venue = Venue.objects.get(id=venue_id)
            try:
                user = STUser.objects.get(user=request.user)
            except:
                user = STUser.objects.get(user=request.session['user_id'])
            
            possible_name = venue.name + "-" + str(date) + "_" + str(artist_ids[0])
            # print "description", description, "poster_id", poster_id, "venue_id", venue_id
            try:
                Event.objects.filter(name=possible_name)[0]
                return HttpResponse(json.dumps({"success":False}), mimetype="application/json")
            except:pass

            
            event = Event()
            event._by = user.user.id
            event.on_date = date
            event.price = price
            event.venue = venue
            event.name = possible_name
            event.description = description
            event.poster = Poster.objects.get(id=poster_id)
            event.save()
            for artist_id in artist_ids:
                artist = Artist.objects.get(id=artist_id)
                event.artists.add(artist)
            
            return HttpResponse(json.dumps({"success":True}), mimetype="application/json")
        except: 
            print traceback.print_exc()    
            return HttpResponse(json.dumps({"success":False}), mimetype="application/json")
        
    if request.method == 'PUT': # inc attends of event, and add this info to user
        try:
            spl = request.raw_post_data.split("=")
            event_id = spl[1]
            event = Event.objects.get(id=event_id)
            event.attends += 1
            event.save()
            
            try:
                stuser = STUser.objects.get(user=request.user)
            except:
                stuser = STUser.objects.get(user=request.session['user_id'])
            stuser.events.add(event)
        
            return HttpResponse(json.dumps({"success":True}), mimetype="application/json")
        except: 
            print traceback.print_exc()    
            return HttpResponse(json.dumps({"success":False}), mimetype="application/json")
        
        
    if request.method == 'DELETE': # deletes event, comes with event_id
        try:
            #print "lele", event_id
            event = Event.objects.get(id=event_id)
            event.delete()
        
            return HttpResponse(json.dumps({"success":True}), mimetype="application/json")
        except: 
            print traceback.print_exc()    
            return HttpResponse(json.dumps({"success":False}), mimetype="application/json")
开发者ID:eleniTheWorldWeekly,项目名称:stagediving,代码行数:104,代码来源:views.py


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