I'm developing a subscription site which includes a 'signup' app. I'm also using a django-oscar shop for one-off purchases and using its UserAddress classes across the whole site. However, as my address and username/email forms are on the same page at subscription signup I use a temporary custom ModelForm based on AbstractAddress with specific fields in signup/forms.py:
# signup/forms.py
from oscar.apps.address.abstract_models import AbstractAddress
class CustomAddressForm(ModelForm):
class Meta:
"""
Using AbstractAddress because UserAddress requires a User and there
is none when signup form is displayed. A UserAddress instance is then
created later, using the User object created after request.POST.
"""
model = AbstractAddress
fields = ['line1', 'line2', 'line4', 'state', 'postcode', 'country']
With INSTALLED_APPS:
# settings.py
from oscar import get_core_apps
INSTALLED_APPS = [
...
'signup',
...
] + get_core_apps()
It's all been working fine in Django 1.8 but I've just tried upgrading to 1.9 prior to deploying and I get the following error message:
File "path/to/python3.4/django/db/models/fields/related.py", line 942, in formfield(self.name, self.remote_field.model))
Cannot create form field for 'country' yet, because its related model 'address.Country' has not been loaded yet
Presumably I could move my custom modelform into the django-oscar core but would rather not.
I've seen this question but as the model in my case is called in the form's Meta fields list as the string 'country', I'm not sure how to import the Country
model here.
I can't find any sign of ModelForms having changed in Django 1.9. Or does anyone know why my form would work in 1.8 but not 1.9?