django foreign key quotes error
Question: I have two models in two files that import one another. One of them is
connected to another by foreign key. To avoid circular import, I am trying to
define the foreign key in quotes:

    
    
    from pubscout.models import Campaign
    class RuleSuite(models.Model):
        campaign = models.ForeignKey('Campaign', verbose_name="Кампания")
    

this has worked before on other models, but this time I get an error:

    
    
      ...
      ...
      File "/Users/1111/.virtualenvs/django_cpa/lib/python2.7/site-packages/django/contrib/admin/checks.py", line 719, in _check_list_filter_item
        get_fields_from_path(model, field)
      File "/Users/1111/.virtualenvs/django_cpa/lib/python2.7/site-packages/django/contrib/admin/utils.py", line 479, in get_fields_from_path
        parent = get_model_from_relation(fields[-1])
      File "/Users/1111/.virtualenvs/django_cpa/lib/python2.7/site-packages/django/contrib/admin/utils.py", line 430, in get_model_from_relation
        return field.get_path_info()[-1].to_opts.model
      File "/Users/1111/.virtualenvs/django_cpa/lib/python2.7/site-packages/django/db/models/fields/related.py", line 661, in get_path_info
        opts = self.remote_field.model._meta
    AttributeError: 'unicode' object has no attribute '_meta'
    

where should I look to fix it?


Answer: You need to qualify model name with application label:

    
    
    campaign = models.ForeignKey('appname.Campaign', verbose_name="Кампания")
    

