def User_Registration(request): if request.method == "POST": form = RegistrationForm(request.POST) if form.is_valid(): user = User.objects.create_user( username=form.cleaned_data["username"], email=form.cleaned_data["email"], password=form.cleaned_data["password"], ) user.save() # users = user.get.profile() # users.name = form.cleaned_data['name'] # users.birthday = form.cleaned_data['birthday'] # users.save() users = Users(user=user, name=form.cleaned_data["name"], birthday=form.cleaned_data["birthday"]) users.save() return HttpResponseRedirect("/") else: return render_to_response("RegisterUser.html", {"form": form}, context_instance=RequestContext(request)) else: """ user is not submitting the form, show them a blank registration form """ form = RegistrationForm() context = {"form": form} return render_to_response("RegisterUser.html", context, context_instance=RequestContext(request))
def create_user(username, password, first_name, last_name, risk_status, cash_amount): new_user = Users(username=username, password=password, first_name=first_name, last_name=last_name, risk_status=risk_status, cash_amount=cash_amount) init_share = Shares(username=new_user, risk_status=new_user.risk_status, cash_amount=new_user.cash_amount) new_user.save() init_share.save()
def save(self, commit=True): user = super(RegistrationForm, self).save(commit=False) user.first_name = self.cleaned_data['first'] user.last_name = self.cleaned_data['last'] user.email = self.cleaned_data['email'] #user.save() if commit: user.save() a = User.objects.get(id=user.id) newusr = Users() newusr.usr_acct = a newusr.isEnrolled = self.cleaned_data['enrled'] newusr.isFaculty = self.cleaned_data['fclty'] deg = Degrees.objects.all() deg = deg[0] newusr.degree = deg newusr.save() return user
import json import os from main.models import Users, Products directory = os.environ['dir'] with open(f'{directory}/users.json', 'r') as users: data = json.load(users) for value in data: users = Users(first_name=value['first_name'], last_name=value['last_name'], birthdate=value['birthdate']) users.save() with open(f'{directory}/products.json') as products: data = json.load(products) for value in data: products = Products(price=value['price'], title=value['title'], description=value['description'], base_discount_percent=value['base_discount_percent']) products.save()