okay, i have a generic question .. I want to have my models.py very clean … no other stuff other than declaring the models.
lets say i have this as models.py
class UserProfile(models.Model:
user = models.OneToOneField(User, related_name='profile')
#other stuff
and this is my signals.py
def create_user_profile(sender, instance, created, **kwargs):
if created:
profile, created = UserProfile.objects.get_or_create(user=instance)
post_save.connect(create_user_profile, sender=User)
how do i go about telling my application that this is my signals file? .. do i have to declare them in my models.py?
//mouse
Well – I saw one way of doing it I liked. Create receivers.py or signals.py in the same app, and put your signal receiving methods and then just import all of them and connect to signals in models.py.
Or even (f.e. if you like to use decorators for defining connected signals, which I always use) – import whole receivers.py at the end of models.py:
from app.receivers import *Only thing I don’t like in this solution is that it sometimes ends with circular dependencies you must care about.