Created
July 30, 2014 16:37
-
-
Save imirzadeh/6ad65aa5f4046798b08e to your computer and use it in GitHub Desktop.
index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load static %} | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Index Page</title> | |
<!-- external scripts --> | |
<!-- jQuery & Bootstrap --> | |
<script type="text/javascript" src="{% static "js/jquery.js" %}"/></script> | |
<script type="text/javascript" src="{% static "js/jquery.jqGrid.min.js" %}"/></script> | |
<link rel="stylesheet" type="text/css" media="all" href="{% static "css/bootstrap.min.css?id=1" %}"/> | |
<script type="text/javascript" src="{% static "js/bootstrap.min.js" %}"/></script> | |
<!-- jQuery & Bootstrap --> | |
<!-- jqGrid --> | |
<link rel="stylesheet" type="text/css" media="screen" href="{% static "css/ui.jqgrid.css" %}" /> | |
<link rel="stylesheet" type="text/css" media="screen" href="{% static "css/ui-lightness/jquery-ui.min.css" %}" /> | |
<script type="text/javascript" src="{% static "js/grid.locale-en.js" %}"/></script> | |
<!-- jqGrid --> | |
<!-- own implemented scripts --> | |
<!-- <script type="text/javascript" src="{% static "js/script.js" %}"/></script> --> | |
<!-- own implemented scripts --> | |
<!-- external scripts--> | |
<script type="text/javascript"> | |
$(function () { | |
$("#list").jqGrid({ | |
url: "http://localhost:8000/getdata", | |
datatype: "json", | |
mtype: "GET", | |
colNames: ["id", "name", "english_title", "capacity"], | |
colModel: [ | |
{ name: "id", index:"id", width: 55 }, | |
{ name: "name", width: 80 }, | |
{ name: "english_title", width: 130, align: "right" }, | |
{ name: "capacity", width: 80, align: "right" }, | |
], | |
rowNum:10, | |
rowList:[10,20,30], | |
pager: '#pager', | |
sortname: 'id', | |
viewrecords: true, | |
sortorder: "desc", | |
multiselect: false, | |
caption: "Rooms", | |
onSelectRow: function(ids) { | |
if(ids == null) { | |
ids=0; | |
if(jQuery("#list_d").jqGrid('getGridParam','records') >0 ) | |
{ | |
console.log(ids); | |
jQuery("#list_d").jqGrid('setGridParam',{url:"getpricelist?q=1&id="+ids,page:1}).trigger('reloadGrid'); | |
} | |
} else { | |
console.log(ids); | |
jQuery("#list_d").jqGrid('setGridParam',{url:"getpricelist?q=1&id="+ids,page:1}).trigger('reloadGrid'); | |
jQuery("#list_d").jqGrid('setCaption',"Price Detail of room : "+ids) | |
} | |
} | |
}); | |
jQuery("#list").jqGrid('navGrid','#pager',{del:false,add:false,edit:false,search:false}); | |
jQuery("#list").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false}); | |
jQuery("#list_d").jqGrid({ | |
height: 100, | |
width:345, | |
url:'getpricelist?q=1&id=2', | |
datatype: "json", | |
colNames:['from','to', 'price'], | |
colModel:[ | |
{name:'from',index:'from', width:100}, | |
{name:'to',index:'to', width:100}, | |
{name:'price',index:'price', width:80, align:"right"}, | |
], | |
rowNum:5, | |
rowList:[5,10,20], | |
pager: '#pager_d', | |
sortname: 'item', | |
viewrecords: true, | |
sortorder: "asc", | |
multiselect: false, | |
caption:"Price Detail" | |
}).navGrid('#pager_d',{add:false,edit:false,del:false}); | |
}); | |
</script> | |
</head> | |
<body> | |
<table id="list"><tr><td></td></tr></table> | |
<div id="pager"></div> | |
<table id="list_d"></table> | |
<div id="pager_d"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from datetime import datetime | |
class room_type(models.Model): | |
id = models.IntegerField(primary_key = True) | |
code = models.CharField(max_length = 40) | |
name = models.CharField(max_length= 40 ) | |
title = models.CharField(max_length = 40) | |
english_title = models.CharField(max_length=40) | |
capacity = models.IntegerField() | |
extra_capacity = models.IntegerField() | |
description = models.CharField(max_length=255) | |
class Meta: | |
db_table = 'room_types' | |
def __unicode__(self): | |
return u'%d' % (self.id) | |
class room_icon(models.Model): | |
id = models.IntegerField(primary_key = True) | |
status = models.IntegerField() | |
color_of_icon = models.CharField(max_length=40) | |
path_of_icon = models.CharField(max_length=255) | |
#foreign_key : a room has only one icon | |
rt_id = models.ForeignKey(room_type) | |
class Meta: | |
db_table = 'room_icons' | |
def __unicode__(self): | |
return u'%d' % (self.id) | |
class attachment(models.Model): | |
id = models.IntegerField(primary_key = True) | |
path_of_pic = models.CharField(max_length=255) | |
#foreign key : a room has many images | |
rt_id = models.ForeignKey(room_type) | |
class Meta: | |
db_table = 'attachments' | |
def __unicode__(self): | |
return u'%d' % (self.id) | |
class price_list(models.Model): | |
id = models.IntegerField(primary_key = True) | |
from_date = models.CharField(max_length=10) | |
to_date = models.CharField(max_length=10) | |
price = models.IntegerField() | |
#foreign key : a room has a pricee list | |
rt_id = models.ForeignKey(room_type) | |
class Meta: | |
db_table = 'price_lists' | |
def __unicode__(self): | |
return u'%d' % (self.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from django.utils import simplejson | |
from django.http import HttpResponse | |
from rooms.models import * | |
from django.db.models import Q | |
from django.core import serializers | |
def index(request): | |
return render(request, 'index.html') | |
def getdata(request): | |
data=room_type.objects.all() | |
json=[] | |
for o in data: | |
json.append({'id':o.id, 'name':o.name, 'english_title':o.english_title, 'capacity':o.capacity}) | |
return HttpResponse(simplejson.dumps(json), mimetype='application/json',content_type='application/json' ) | |
def getpricelist(request): | |
requested_room_id = request.GET.get('id', '') | |
room = room_type.objects.get(id = requested_room_id) | |
price_list_set = room.price_list_set.all() | |
json=[] | |
for price_list in price_list_set: | |
json.append({'from':price_list.from_date, 'to':price_list.to_date, 'price':price_list.price}) | |
return HttpResponse(simplejson.dumps(json), mimetype='application/json',content_type='application/json' ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment