[Fixed]-RelatedObjectDoesNotExist

1👍

In the line:

auth = Authenticator(authenticator = "matt")

You attempt to initialize an Authenticator with an “authenticator” property value "matt". Since you declared that this attribute should be a user model, you should assign a User instance here. Something like:

auth = Authenticator(authenticator=User(name="matt"))

might be closer to what you are trying to do (I don’t know the structure of your user model, obviously).

Beyond that, some pieces of unsolicited coding advice:

  • Use PEP8
  • The name authenticator as an attribute of the Authenticator is confusing; user might make a lot more sense here since it is the the user attribute of this authenticator
  • Avoid print statements and testing multiple assertions in your individual tests
  • Accessing another model in your __unicode__ method introduces two issues – it will cause a database lookup which is likely to produce N+1 scenarios and it is more likely to throw an error, which will make the string representation of this model in such a scenario unusable and complicate debugging/logging

Leave a comment