def create_profile(sender, **kw): if 'instance' not in kw or not kw.get('created', False): return instance = kw['instance'] profile = UserProfile() profile.user = instance bc, im = create_barcode(u'USER-{0}'.format(instance.username[0]), instance.id, instance.username) profile.barcode = bc content = ContentFile(im) profile._barcode.save('{0}.png'.format(bc), content) profile.save()