Re: post_save signal is not dispatched

2018-06-24 Thread Melvyn Sopacua
On zondag 24 juni 2018 15:45:47 CEST Dejan Spasić wrote:
> def post_save_user(**kwargs: Dict[str, Any]) -> None:
> if kwargs['created']:
> return None

So for new users, you bail out and do nothing. Your code works exactly as you 
wrote it.

-- 
Melvyn Sopacua

-- 
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/1595824.LYJT9xCsNO%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: post_save signal is not dispatched

2018-06-24 Thread Dan Tagg
Hi,

Weirdly, I've just been doing this. What do you have in your settings
INSTALLED_APPS?

One of them should be something like 'employer.apps.EmployerConfig'
alternatively in your employer module's __init__.py file you need to say
default_app_config = 'employer.apps.EmployerConfig'

Dan

On 24 June 2018 at 14:45, Dejan Spasić  wrote:

> I don't wont to bother you with a long text and will first show you the
> code. I think this should be self explanatory. If not, let me know :)
>
> #
>
> from typing import Any, Dict
>
> from django.apps import AppConfig
> from django.db.models.signals import post_save
>
> from django.contrib.auth.models import User
> from .models import Employer
>
>
> class EmployerConfig(AppConfig):
> name = "employer"
> verbose_name = "Employer"
>
> def ready(self) -> None:
> def post_save_user(**kwargs: Dict[str, Any]) -> None:
> if kwargs['created']:
> return None
>
> user: User = kwargs['instance']
>
> if user.employer:
> return None
>
> employer = Employer(user=user)
> employer.save()
>
> post_save.connect(post_save_user, User)#
>
>
> As you can see I want to create an employer and link them with the new 
> created user.
>
> Running the command
>
> ./manager.py createsuperuser --username username --email u...@user.com 
> ***
>
> shows me that I'm wrong. There is no entry in the myapp_employer table. What 
> did I missend?
>
>
> * Django: 2.0.X
> * app is installed
>
> * python: 3.6
>
>
> --
> 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/8d0c4241-3d1a-46c9-9e52-6cc4f46a3906%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Wildman and Herring Limited, Registered Office: 28 Brock Street, Bath,
United Kingdom, BA1 2LN, Company no: 05766374

-- 
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/CAPZHCY562U_NDqLeKgfEGvGOz3Un9u8k0RHaiHTg_AYts_UFzw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


post_save signal is not dispatched

2018-06-24 Thread Dejan Spasić
I don't wont to bother you with a long text and will first show you the 
code. I think this should be self explanatory. If not, let me know :)

#

from typing import Any, Dict

from django.apps import AppConfig
from django.db.models.signals import post_save

from django.contrib.auth.models import User
from .models import Employer


class EmployerConfig(AppConfig):
name = "employer"
verbose_name = "Employer"

def ready(self) -> None:
def post_save_user(**kwargs: Dict[str, Any]) -> None:
if kwargs['created']:
return None

user: User = kwargs['instance']

if user.employer:
return None

employer = Employer(user=user)
employer.save()

post_save.connect(post_save_user, User)#


As you can see I want to create an employer and link them with the new created 
user. 

Running the command 

./manager.py createsuperuser --username username --email u...@user.com 
***

shows me that I'm wrong. There is no entry in the myapp_employer table. What 
did I missend?


* Django: 2.0.X 
* app is installed 

* python: 3.6


-- 
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/8d0c4241-3d1a-46c9-9e52-6cc4f46a3906%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.