When I try to migrate my project from empty DB state, it falls into a 
vicious cycle: Trying to migrate it requests Country.objects.all() because 
it has form fields using PlaceWidget but this requires it to be already 
migrated.

How to solve this problem?

class PlaceWidget(widgets.MultiWidget):
    template_name = 'core/widgets/placewidget.html'

    class Media:
        js = ('js/placewidget.js',)

    def __init__(self, attrs=None):
        _widgets = (
            widgets.Select(choices=[('', '-')] + [(c.pk, c.name) for c in 
Country.objects.all().order_by('name')],
                           attrs={'onchange': "update_places_list(1)", **(attrs 
or {})}),
            widgets.Select(choices=[('', '-')],
                           attrs={'onchange': "update_places_list(2)", **(attrs 
or {})}),
            widgets.Select(choices=[('', '-')],
                           attrs={'onchange': "update_places_list(3)", **(attrs 
or {})}),
            widgets.Select(choices=[('', '-')],
                           attrs={'onchange': "update_places_list(4)", **(attrs 
or {})}),
            widgets.Select(choices=[('', '-')])
        )
        super().__init__(_widgets, attrs)

    def decompress(self, value):
        if value:
            return [value['country'].pk if value['country'] else None,
                    value['region'].pk if value['region'] else None,
                    value['subregion'].pk if value['subregion'] else None,
                    value['city'].pk if value['city'] else None,
                    value['district'].pk if value['district'] else None]
        return [None, None, None, None, None]


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1f97161d-04bc-47be-aecb-1c3796bfdae7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to