1. Chris Moffitt
  2. satchmo
  3. Issues
Issue #1210 resolved

order.status is set to None if an order is saved in the Admin while using ReadOnlyWidget

John Schulte
created an issue

Running Django 1.2.1 and Satchmo 0.9.1.

Every time I edited an order and saved it in the admin, the order.status was being set as None.

I changed shop/admin.py from: {{{

!python

def formfield_for_dbfield(self, db_field, **kwargs):
    read_only = ['status']
    field = super(OrderOptions, self).formfield_for_dbfield(db_field, **kwargs)
    if db_field.name in read_only:
        field.widget = ReadOnlyWidget()
    return field

}}}

To: {{{

!python

def formfield_for_dbfield(self, db_field, **kwargs):
    read_only = []
    field = super(OrderOptions, self).formfield_for_dbfield(db_field, **kwargs)
    if db_field.name in read_only:
        field.widget = ReadOnlyWidget()
    return field

}}}

Which makes it such that the ReadOnlyWidget is not used for the status field. This fixed the problem, which leads me to believe that the problem is with the ReadOnlyWidget. The fact that other Sachmo users have not complained of this bug makes me think that it has something to do with the Version of Django that I'm using.

Comments (7)

  1. John Schulte reporter

    OK I just tried Django 1.2's read only field:

    class OrderOptions(AutocompleteAdmin):
        fieldsets = (
            (None, {'fields': ('site', 'contact', 'method', 'status', 'discount_code', 'notes')}), (_('Shipping Method'), {'fields':
                ('shipping_method', 'shipping_description')}), (_('Shipping Address'), {'classes': ('collapse',), 'fields':
                ('ship_street1', 'ship_street2', 'ship_city', 'ship_state', 'ship_postal_code', 'ship_country')}), (_('Billing Address'), {'classes': ('collapse',), 'fields':
                ('bill_street1', 'bill_street2', 'bill_city', 'bill_state', 'bill_postal_code', 'bill_country')}), (_('Totals'), {'fields':
                ('sub_total', 'shipping_cost', 'shipping_discount', 'tax', 'discount', 'total', 'time_stamp')}))
        list_display = ('id', 'contact', 'time_stamp', 'order_total', 'balance_forward', 'status', 'invoice', 'packingslip', 'shippinglabel')
        list_filter = ['time_stamp', 'contact', 'status']
        date_hierarchy = 'time_stamp'
        list_filter = ['time_stamp', 'status']
        date_hierarchy = 'time_stamp'
        search_fields = ('contact__first_name', 'contact__last_name', 'contact__email')
        related_search_fields = {'contact': ('first_name', 'last_name', 'email')}
        related_string_functions = {'contact': lambda c: u"%s <%s>" % (c.full_name, c.email)}
        inlines = [OrderItem_Inline, OrderStatus_Inline, OrderVariable_Inline,
            OrderTaxDetail_Inline, OrderAuthorizationDetail_Inline,
            OrderPaymentDetail_Inline, OrderPaymentFailureDetail_Inline]
        #Using Django 1.2's read only field
        readonly_fields = ('status')
    

    I looks fine while I was editing an order. But upon saving order.status was set to None just like the original ReadOnlyWidget.

  2. Chris Moffitt repo owner

    In 646f52cc93eb I removed the custom widget and replaced with Django's. I was able to reproduce your original error and this fixed it for me.

    I will leave this open since it seems you're still having some issues.

  3. Log in to comment