0

Here is a brief sample of the model setup and the query I am trying. This didn't give me any errors in Django 1.6, but in 1.7 it gives me an exception. The "implicit" foreign key is not available on the Interface queryset, it seems. I tried both select_related('gwportprefix') and prefetch_related('gwportprefix') with no luck.

class Interface(models.Model):
    # Several fields here that are not related.
    pass

class GwPortPrefix(models.Model):
    interface = models.ForeignKey('Interface', db_column='interfaceid')

for gwport in Interface.objects.filter(gwportprefix__isnull=False):
    gwport_matches.add(gwport)

This gives the following FieldError:

Cannot resolve keyword 'gwportprefix' into field. Choices are (Everything directly on Interface. No implicit foreignkeys)

1 Answer 1

1

in django 1.7 many changes occurred in the QuerySet / Manager implementation. Have you tried ?

Interface.objects.filter(gwportprefix_set__isnull=False)
1
  • Gives me the same exception with keyword 'gwportprefix_set' instead.
    – lizter
    Dec 17, 2014 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.