global name 'OrderVariable' is not defined

Create issue
Issue #1328 resolved
Irfan Ahmad created an issue

The error occurs when we try to append an order variable to an order using function //add_variable// of model Order

Here is the code from satchmo/apps/satchmo_store/shop/models.py

{{{ def add_variable(self, key, value): """Add an OrderVariable, used for misc stuff that is just too small to get its own field""" try: v = self.variables.get(key__exact=key) v.value = value except OrderVariable.DoesNotExist: v = OrderVariable(order=self, key=key, value=value) v.save() }}}

Notice that in exception handling, a new variable v is being created of type OrderVariable whereas it is not defined yet.

=== Suggesstion: ===

Move OrderVariable above Order and lazy refernce Order there like this:

{{{

order = models.ForeignKey("Order", related_name="variables") }}}

Comments (1)

  1. Log in to comment