On 5/11/2016 12:24 AM, David Unric wrote:
I'd like replace field type for billing/shipping country, at
cartridge.shop.models.Order model.
Instead of plain CharField I'd like use CountryField from
django_countries.
Is that possible with Mezzanine and how ?
settings.EXTRA_MODEL_FIELDS does not work, it throws an exception same
named field already exists. It sounds logical as it serves for
/extending/ models, not replacing.
I can't also find a setting to specify alternate class for Order model
so it seems subclassing won't be an option.
Any better idea then a fuzzy conversion to/from CountryField in custom
form ?
It's not all that difficult. I've done something similar with a custom
OrderForm class in cartridge-braintree (now maintained by Henri)
https://github.com/henri-hulski/cartridge_braintree/blob/master/cartridge_braintree/forms.py#L77-L83
So basically:
- Create a subclass of OrderForm
- Override the country field widgets
- and in urls.py, use this Order Form as the one used by the shop (pass
form_class=myapp.forms.MyOrderForm, when calling the shop/checkout views)
(Old style would be to use SHOP_CHECKOUT_FORM_CLASS but that's not
recommended for Django 1.8 onwards)
Seeya. Danny.
--
You received this message because you are subscribed to the Google Groups "Mezzanine
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.