Well all of the models are part of the same application. So here is the code:
models.py: <pre> from django.db import models from django.db.models import signlas from django.dispatch import disaptacher from asqcom.apps.staticpages import signals from asqcom.abstract_models import CommonAbstractModel class Link(CommonAbstractModel): url = models.CharField(max_length=1024) title = models.CharField(max_length=64) text = models.CharField(max_length=64) class Meta: verbose_name = 'static page' verbose_name_plural = 'static pages' ordering = ('url',) def __unicode__(self): return u"%s - %s" (self.text, self.url,) class Menu(CommonAbstractModel): name = models.CharField(max_length=64) title = models.CharField(max_length=64) # used in the <title> links = models.ManyToManyField(Link) class Meta: verbose_name = 'menu' verbose_name_plural = 'menus' ordering = ('name',) def __unicode__(self): return u"%s" % (self.name) def to_xhtml(self): pass class StaticPage(CommonAbstractModel): url = models.CharField(max_length=128, db_index=True) title = models.CharField(max_length=256) content = models.TextField(blank=True) menu = models.ForeignKey(Menu, null=True, blank=True) template_name = models.CharField(max_length=70, blank=True) registration_required = models.BooleanField() class Meta: verbose_name = 'static page' verbose_name_plural = 'static pages' ordering = ('url',) def __unicode__(self): return "%s - %s (menu: %s)" % (self.title, self.url, self.menu or 'no menu',) class CachedMenuXhtml(CommonAbstractModel): menu = models.ForeignKey(Menu) xhtml = models.TextField() def __unicode__(self): return self.xhtml dispatcher.connect(signals.build_menu_from_link_mod, signal=signals.signals.post_save, sender=Link) dispatcher.connect(signals.build_menu_from_menu_mod, signal=signals.signals.post_save, sender=Menu) </pre> signals.py: <pre> import threading from asqcom.apps.staticpages.models import Link, Menu, StaticPage from asqcom.apps.staticpages.models import CachedMenuXhtml class GenerateMenuXhtmlByLink(threading.Thread): def __init__(self, instance): self.instance = instance threading.Thread.__init__(self) def run(self): pass class GenerateMenuXhtmlByMenu(threading.Thread): def __init__(self, instance): self.instance = instance threading.Thread.__init__(self) def run(self): pass def build_menu_from_link_mod(... def build_menu_from_menu_mod(.. I hope this better specifies the issue. Should I import these in the run method for each Thread subclass? On Jul 8, 4:47 pm, Alex Gaynor <alex.gay...@gmail.com> wrote: > On Wed, Jul 8, 2009 at 3:45 PM, Ryan K <ryankas...@gmail.com> wrote: > > > I am creating an application that uses the dispatcher in Django. In > > the apps models.py file I connect the post_save of two models to > > functions in a signals.py file. The problem is that I need to use > > several models in models.py and that leads to a circular import. What > > is the best way to solve this problem? > > > Cheers, > > Ryan > > Depending on how you're using these other models you can a) do imports > inside of functions, or > b)http://docs.djangoproject.com/en/dev/ref/models/fields/#lazy-relation.... > Or both (probably this) > > Alex > > -- > "I disapprove of what you say, but I will defend to the death your right to > say it." --Voltaire > "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---