def post(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) customer = Customer() customer.name = serializer.data['name'] customer.email = serializer.data['email'] customer.tax_id = serializer.data['tax_id'] customer.save() headers = self.get_success_headers(serializer.data) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
def sign_up(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') user = User.objects.get(username=username) group = Group.objects.get(name="Customer") user.groups.add(group) customer = Customer(user=user, address=form.cleaned_data.get('address'), phone=form.cleaned_data.get('phone')) customer.save() return redirect('dashboard') else: form = SignUpForm() return render(request, 'registration/signup.html', {'form': form})
def save(cls, data, instance=None): try: customer_name = data.get('customer_name', '') ticket = instance if instance else Ticket() with transaction.atomic(): for key, value in data.items(): setattr(ticket, key, value) if customer_name: if ticket.customer_id: customer = CustomerService.get(ticket.customer_id) else: customer = Customer() customer.name = customer_name customer.save() ticket.customer_id = customer.id ticket.save() return ticket except Exception as ex: # todo: handle log raise ex
amount_of_places=4, color=fake.color_name(), engineer=engineer, park=park, car_plate=2) customer = Customer(username=fake.user_name(), first_name=fake.first_name(), last_name=fake.last_name(), email=fake.free_email(), country=fake.country(), zipcode=fake.postcode(), city=fake.city(), phone_number=fake.phone_number(), operator=operator, car=car) customer.save() for i in range(0, 300): try: charging_station = ChargingStation.objects.get( uid=random.randint(0, 2)) except ChargingStation.DoesNotExist: charging_station = ChargingStation(uid=0, price=25, amount_of_available_sockets=25, gps_location='234 412', size_of_plug=2, shape_of_plug=2) try: car = Car.objects.get(car_id=random.randint(0, 99)) except Car.DoesNotExist: