I tried but i don't seem to be getting it, please help Views.py from django.contrib import messages from django.contrib.auth.decorators import login_required from django.http import Http404 from django.shortcuts import render, redirect from .forms import DepositForm, WithdrawalForm from users.models import Profile import random from . import models
def random_gen(): # return a 10 digit random number return int(random.uniform(1000000000, 9999999999)) def index(request): try: curr_user = Profile.objects.get(user=request.user) # getting details of current user except: # if no details exist (new user), create new details curr_user = Profile() curr_user.account_number = random_gen() # random account number for every new user curr_user.balance = 0 curr_user.user = request.user curr_user.save() return render(request, "users/profile.html", {"curr_user": curr_user}) *models.py* from django.db import models from django.contrib.auth.models import User from PIL import Image class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) image = models.ImageField(default='default.jpg', upload_to='profile_pics') account_number = models.IntegerField(blank=False,null=False) balance = models.IntegerField(blank=False,null=False) def __str__(self): return f'{self.user.username} Profile' def save(self, *args, **kwargs): super(Profile, self).save(*args, **kwargs) img = Image.open(self.image.path) if img.height > 300 or img.width > 300: output_size = (150, 150) img.thumbnail(output_size) img.save(self.image.path) -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9fc94f46-9826-4d85-ab98-ebbb50dad5d8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.