python - Django Datetime Issue -
what trying isn't difficult, isn't working. cannot see error is. in abstract user model have is_donator method not work.
@property def is_donator(self): if(self.donator >= datetime.now()): return true else: return false
some reason not return anything, looks alright me though, ideas?
you have 2 related issues. first using wrong comparison.
if(self.donator >= datetime.now()):
this means donor must become donor @ point in future.
change
if(self.donator <= datetime.now()):
this ensure became donor in past.
the other issue have using auto_now:
automatically set field every time object saved. useful “last-modified” timestamps. note current date used; it’s not default value can override.
this, then, relates first issue. every time user field updated - if don't explicitly set field - defaults now.
update based on comments: checking if donator not null , ensure exists. if doesn't exist, determine logic, though if doesn't exist, user isn't donator. can return false
in except
block. block pretty verbose, shows explicitly happening.
def is_donator(self): try: if self.donator: # checking self.donator not null if(self.donator >= datetime.now()): return true else: return false else: # return false? # runs if self.donator null except nameerror: # (or 'pass', because self.donator value doesn't exist)
Comments
Post a Comment