def setUp(self): self.station = Station(name='MyTestStation') self.station.save() self.box = Box(station=self.station, address='My address str. 4') self.box.save() self.stand = Stand(box=self.box, name='MyStand') self.stand.save() self.service = Service(name='TestService', min_duration=datetime.timedelta(minutes=30), max_duration=datetime.timedelta(minutes=30), min_cost=500, max_cost=1000) self.service.save()
def add_station_view(request): params = json.loads(request.body) company_id = params.get('company') company = Company.objects.get(id=company_id) station = Station() station.name = params.get('name') station.capacity = params.get('capacity') station.mode = params.get('mode') station.is_self_consume = params.get('is_self_consume') station.is_self_consume_discount = params.get('is_self_consume_discount') station.company = company station.save() return json_response(station.to_dict())
def new_station(request): if request.method == 'POST': # save new post name = request.POST['name_station'] num_station = request.POST['num_station'] date_creation = datetime.now() station = Station(name=name, num_station=num_station, date_creation=date_creation) station.save() stations = Station.objects return HttpResponseRedirect('/') else: return render(request, 'new_station.html')