Then, inside the signals, do "from webapp.app import models"
Then attach the signals in a fashion which you are accustom to (see
http://docs.djangoproject.com/en/dev/topics/signals/).
Then, inside the __init__.py OR the models.py, do "import
webapp.app.signals"
I do not know if Django checks if a signal has already been attached, so
you might want to unit test this first.
On 01/12/2010 21:32, garagefan wrote:
> That wouldn't resolve the problem any more than having everything in
> the models.py.
>
> i wish to externalize this signal from the gallery application so that
> it is up to the website project whether or not a signal is being used.
> i suppose i could add a toggle variable in the gallery settings file
> so the project settings file can decide whether or not to utilize the
> work being done within the method via a local variable...
>
> seems kind of a messy way to do things... it'd be great to have a
> single file for the website's signals... sort of like setting up
> templatetags at the project level
>
>
> On Dec 1, 3:28 pm, Daniel Roseman<dan...@roseman.org.uk> wrote:
>> On Dec 1, 5:29 pm, garagefan<monkeygar...@gmail.com> wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> Now, i've read the thread in regards to putting the import in the
>>> __init__.py
>>> here is my structure
>>> website_project
>>> -> signals
>>> - -> signals.py (and an __init__.py)
>>> -> shared_apps (link to numerous apps shared amongst other projects)
>>> - -> gallery application
>>> my signals.py looks like this
>>> from django.db.models.signals import post_save
>>> from django.core.mail import send_mail
>>> from gallery.models import Gallery
>>> def send_creation(sender, instance, *args, **kwargs):
>>> if 'created' in kwargs:
>>> if kwargs['created'] and instance.published:
>>> send_mail('Subject here',[sender, instance.published,
>>> args, kwargs,], 'f...@example.com', ['...@example.com'],
>>> fail_silently=False)
>>> post_save.connect(send_creation,sender=Gallery)
>>> this works when in the gallery application, however... this is just a
>>> test case, eventually i am going to be hitting up the fb graph api and
>>> posting the website's facebook profile, and i'd prefer to keep the
>>> gallery application useful for both facebook and non-facebook
>>> integrated websites.
>>> I've attempted import signals and import signals.signals in the
>>> website_project __init__.py. the former resulting in nothing and the
>>> latter resulting in a "internal server failure" upon restart.
>> You should do this the other way round. Keep the signal definition -
>> the `send_creation` function itself - in signals.py, but don't import
>> Gallery there. Instead, in gallery/models.py, import the *signal*:
>> from signals.signals import send_creation - and then do the
>> registering at the bottom of that file.
>> --
>> DR.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment