Posts

Showing posts from November, 2014

Export Data from QuerySet as Excel File in Django

Let's say you have this function in your views.py: def funtion_name(request): if request.method == "GET": get_id = request.user.id ... ... ... args = [] kwargs = { 'landproperty__sownerid__id': get_id, 'geom__distance_lte': (pnt, D(km=kmdistance)), 'narea__lte': getarea } mm = YourModelHere.objects.filter(*args, **kwargs).values_list('fielname1', 'fielname2', 'fielname3','fielname4') request.session[0] = mm return HttpResponse(json.dumps(list(m)), content_type='application/json') In order to get or pass the QuerySet from this function, you need to store it in a session as shown above. Here's how to create an excel file: def create_excel(request): book = xlwt.Workbook(encoding='utf8') sheet = book.add_sheet('untitled') default_style = xlwt.Style.defa...

I like her a lot...

Image
I like her a lot that I stop and just stare her smile like forever. What the F***! I always love cute people and those who smiles like an anti-inflammatory capsule. Women really are powerful  being! Like drugs, they can ease pain and worsen it. They're like a double-edge sword. :D Too bad, I'm so pessimistic! But I think, just this time I'll be hopeful. hahaha Like I always say, for a long time I don't like being close to a woman, like having a romantic closeness. Sounds gay! hahaha It's a choice! I do date sometimes but I just thought that I don't need a girlfriend that time. Too many reasons, right? I guess all those reasons won't matter if your feeling towards that girl is greater than those reasons. It's all about their weight. And the song for this babble,  

#MusicPlaylist 1: Getting a Good Night's Sleep

Image
I usually don't play music when I want to sleep 'cause sometimes I sing along with it. I have to tell you this Cause my heart goes wild -Russian Red

Electric-Lorde

Image
When in comes to dancing, Lorde is the BEST! :D I really love her, it makes my jaw drops and think of something weird. That's how good she is, actually she's just feelin' the song.  Nah...just watch this video.

Changing password in Django

Image
Add this to your urls.py: url(r'^accounts/change-password/', 'django.contrib.auth.views.password_change', {'post_change_redirect' : '/accounts/password-changed/'}), url(r'^accounts/password-changed/', 'django.contrib.auth.views.password_change_done'), Just edit the links above. Then in you templates folder, create new folder and name it   registration .  . Then create this html file below: password_change_form.html {% extends "edit_profile.html" %} {% block head_title %}Change Password{% endblock %} {% block content %} <div class="jumbotron" style="width: 940px; margin: 80px auto; border-radius: 5px;"> <form method="post" action="."> {% if next %} <input type="hidden" name="next" value="{{ next }}" /> {% endif %} {{form.as_p}} <input type="submit" value=...

Serializing Objects and Passing Multiple JSON Data in Django

Image
Below is just an example, just replace the necessary Models and Queries: def pins_info(request): if request.method == "GET": getpin = request.GET.get('pin', None) keyvals = OrderedDict([ ('taxdec', 'landproperty__ctaxdec'), ('brgy', 'ssectionid__sbrgyid__cbrgyname'), ('landarea', 'narea') ]) keyvals1 = OrderedDict([ ('mydescription', 'description') ]) m = ButuanMaps.objects.filter(clandpin=getpin).values_list(*keyvals.values()) reference = ButuanMaps.objects.get(clandpin=getpin).geom within = SoilType.objects.filter(geom__contains=reference).values_list(*keyvals1.values()) within1 = ErosionMap.objects.filter(geom__contains=reference).values_list(*keyvals1.values()) result = dict(zip(keyvals, zip(*m))) result1 = dict(zip(keyvals1, zip(*within))) result2 = dict(zip(keyvals1, zip(*within1))) data = json.dumps([result, result1, result2], cls=DjangoJSONEncoder) ret...