Closed FrViPofm closed 10 years ago
Hi, You can write below, If you want to use dummy object for a new object.
try:
song = Song.get(id)
except Song.DoesNotExist:
pass
else:
song = Song(lang="fr")
return dict(object=song)
The constructor of "Song" creates a object which is created on database. It can be use as a new object in the session.
Sorry, I've mistaken. The constructor of "Song" creates a object which will not be created on the database. The object can be use for a new record on web pages without saving into the database.
Is it possible to have a dummy classmethod for writing such code :
@get("/song/id:int/edit") @get("/song/_new") @view("song.edit.html") def song_edit(id = -1): """Edits song""" if id > 0: try: song = Song.get(id) except Song.DoesNotExist: pass else : song = Song.dummy(lang="fr") return dict(object=song)
This would avoid creating an object in the database if the action is canceled. This would permit to use the same template for creating a new object or editing an existing one.