title: Django signals > right approach?
body: <p>In my <strong>signals.py</strong> I am doing the import for the function <code>unique_order_reference_generator</code> within the function <code>reserveditem_create_order_reference</code>. I wonder if that is the right approach, or is there a better solution?</p>
  
  <p>file <strong>utils.py</strong></p>
  
  <pre><code>from lumis.utils import get_random_string
  
  from .models import Order, ReservedItem
  
  
  def unique_order_reference_generator():
  
      new_id = get_random_string(length=10)
  
      reserved_item = ReservedItem.objects.filter(
          order_reference=new_id
      ).exists()
      order = Order.objects.filter(order_reference=new_id).exists()
  
      if reserved_item or order:
          return unique_order_reference_generator()  # TODO Marc: Test
      else:
          return new_id
  </code></pre>
  
  <p>file <strong>signals.py</strong></p>
  
  <pre><code># Generate order reference
  def reserveditem_create_order_reference(sender, instance, **kwargs):
      from .utils import unique_order_reference_generator
  
      if not instance.order_reference:
          instance.order_reference = unique_order_reference_generator()
  </code></pre>
  
  <p>file <strong>app.py</strong></p>
  
  <pre><code>class OrdersConfig(AppConfig):
      name = 'orders'
  
      def ready(self):
  
          #Pre save signal for ReservedItem model
          reserved_model = self.get_model('ReservedItem')
          pre_save.connect(
              reserveditem_create_order_reference,
              sender=reserved_model,
              dispatch_uid="my_unique_identifier"
          )
  </code></pre>