def post(self, request): try: account = Account.objects.get(manager=request.user, pk=request.POST.get('account_id')) except Account.DoesNotExist: return {'error': True, 'errors': [u'Неизвестный аккаунт']} form = AccountForm(request.POST, instance=account) if not form.is_valid(): return {'error': True, 'errors': get_all_form_errors(form)} form.save(commit=True) return {'error': False}
def post(self, request): form = AccountForm(request.POST, initial={'manager': request.user}) form.instance.manager = request.user if not form.is_valid(): return {'error': True, 'errors': get_all_form_errors(form)} # try: form.save(commit=True) except IntegrityError: return {'error': True, 'errors': [u'Такой аккаунт уже есть в базе данных']} return {'error': False}