def get_default(): cfilter = Community.objects.filter(name="Princeton") if cfilter.count() == 0: logger.debug("Creating a default community of Princeton") c = Community(name="Princeton", descr="Default Community of Princeton", city="Princeton",state="NJ") c.save() return c else: return cfilter[0]
def post(self,request,format): try: json_raw = request.body.decode(encoding='UTF-8') obj = json.loads(json_raw) try: u = User.objects.get(username=obj["comm_leader"]) entity = Community( comm_leader = u, comm_name = obj["comm_name"],comm_description = obj["comm_description"]) entity.save() except ObjectDoesNotExist: return HttpResponse(json.dumps({"msg" : "The Leader doesn't exist"}), content_type='application/json') return HttpResponse(json.dumps({"msg" : "The community was added successfully"}), content_type='application/json') except Exception, e: return HttpResponse( json.dumps({"e" : str(e)}) )