1

I've been searching around trying to figure this out, I want to add simple things to my Profile model like avatar, contact info, etc. However when following tutorials that I found online on how to do this, I am only met with errors.

This is what my model looks like (tracks/models.py):

from django.db import models from django.core.exceptions import ValidationError from django.core.files.images import get_image_dimensions from django.contrib.auth.models import User ... class Profile(models.Model): def generate_user_folder_avatar(instance, filename): return "uploads/users/%s/%s.png" % (instance.user, 'avatar') user = models.OneToOneField(User) avatar = models.ImageField(upload_to=generate_user_folder_avatar,validators=[is_square_png]) def create_user_profile(sender, instance, created, **kwargs): if created: Profile.objects.create(user=instance) post_save.connect(create_user_profile, sender=User) 

I've set the AUTH_PROFILE_MODULE = 'tracks.Profile' in settings.py but when I run my server I get this error:

NameError: name 'post_save' is not defined 

Any idea what I am doing wrong here? I'm using Django 1.9 and Python 3

1 Answer 1

6
NameError: name 'post_save' is not defined 

you should do the import:

from django.db.models.signals import post_save 

note #1: you may be interested in the fact that Django provides more explicit and clear way to extend User model: https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#extending-django-s-default-user

note #2: you probably want to connect signals not somewhere in models, but like that: https://stackoverflow.com/a/21612050/699864

Sign up to request clarification or add additional context in comments.

2 Comments

Actually, the next answer is more apt: stackoverflow.com/a/21612050/1628832 for point #2
@karthikr ty! replaced the link for the note #2.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.