Hi Everyone, I'd like to propose a small change to django.db.models.Model to make it neater to determine whether or not a model object is already stored in the database. Either:
Option 1: Rename the _get_pk_val() method to get_pk_val(), marking it safe for public use. Option 2: Add a method named is_saved() which checks the value of the primary key. Here's the situation that inspired the proposal. I'm in the midst of some code to push objects in and out of custom FormManipulators. At several points, the code needs to determine whether or not the model objects are stored in the database, in order to know whether the object should be deleted. Since my model classes don't explicitly define primary keys, this is fairly simple - it's just a matter of checking model_object.id. Since I was doing it several times, I made up a utility method, "is_saved(model_object)". I now have this kind of code: if is_saved(object): object.delete() However, that doesn't look right - model objects know whether or not they've been saved, and should be able to communicate that without requiring the programmer to know the primary key name. I would have used django.db.models.Model._get_pk_val() method, except for the leading underscore marking the method as being for private use. Hence the first option, at the top of this email. If exposing the primary key value like that would be undesirable, a more modest option would be a simple "is_saved()" method. Does either of these options sound reasonable? If so, I'm happy to make up a patch, including changes to db-api.txt. Alan. -- Alan Green [EMAIL PROTECTED] - http://bright-green.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---