"Approved" field with timestamp
I wanted to make the objects of a particular model approvable and store the timestamp of when that happened. In other frameworks/languages, I used to combined those in one "approved_at" field, which would be NULL if an object was currently unapproved.
I tried different approaches to implement this in django, and this is the best I came up with so far. Basically, the code in setattr makes sure that the field, once set, will not be updated again.
Overriding setattr__() could also be a solution to determining if a field value has changed in save(), a question that seems come up from time to time in #django.
Yeah, you're right. If that's the case, simple is probably good enough for you.
For me it's a little bit more complicated, as in an international site, I'll have to deal with more complex, region-based approval process.
My models has been evolving into a more complex solution to accommodate the needs of my clients, but I haven't yet found something that I'm truly happy with.
pjanderson: I know that depending on one's needs, this can be a complex issue.
However, in my case, I usually want to implement an option to withold a piece of content temporarily before it gets finally published (basically a simple draft machanism), and just use that opportunity to store a timestamp as well, only because it can't hurt ;)
There's usually only a limited group of trusted administrative users, so that's good enough for me most of the time.
I'm working on a project where all user-contributed content needs to be approved.
What I came to realize is that this is not a trivial problem. If you model is, let's say, a blog Entry, and to keep things simple :), you decide to store Entry options (enable_comments, is_public, is_shared, is_published, etc) in the same model as Entry content, what will happen if the user decides to change some of the options or content after the object has been approved. How will you decide if the object should remain approved, or should be sent back for approval?
I'm not sure that setting a date as the Model field to denote approval state is the best solution. Perhaps there should be a separate table with options and approval state. Someone could even take it further by logging each approval state change.
I guess it depends on the needs of the program and the approval process, but you might soon realize that your approach has limitations, though it's probably sufficient for a quick and simple representation.
I haven't found the best solution yet, but these are issues I'm dealing with.