Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • Thx but it Didnt work for me... the same error pops up and the "if not self.author" statement doesnt even get executed.... Commented Dec 20, 2020 at 5:07
  • i made some changes n tried so it works..but i need to add this if condition everywhere else i wanna use the username Commented Dec 20, 2020 at 7:25
  • Yes, of course. If you want to access an attribute of something, you need to ensure it exists everywhere you want to use it. Making it a property of your model would make this much easier and avoid the repetition of the condition. Commented Dec 20, 2020 at 11:25