Files
2012-02-21 01:15:00 -05:00

1 line
6.2 KiB
JSON

[{"user_id": 14492, "stars": [], "topic_id": 8600, "date_created": 1298523394.361969, "message": "what I want to do is to automatically set \"Active\" to False if 'today' is past \"end\" date", "group_id": 81, "id": 195392}, {"user_id": 14492, "stars": [], "topic_id": 8600, "date_created": 1298523544.513654, "message": "i believe this must be really simple, but I'm not a programmer and I have no programming fundamentals.. :/", "group_id": 81, "id": 195416}, {"user_id": 1736, "stars": [], "topic_id": 8600, "date_created": 1298523597.8497961, "message": "Use Celery", "group_id": 81, "id": 195423}, {"user_id": 14492, "stars": [], "topic_id": 8600, "date_created": 1298523328.7766321, "message": "I have a model with two DateTime fields. One marks the creation date and the other the \"End\" date.", "group_id": 81, "id": 195376}, {"user_id": 14492, "stars": [], "topic_id": 8600, "date_created": 1298523337.992337, "message": "It also has an \"active\" boolean field.", "group_id": 81, "id": 195379}, {"user_id": 14492, "stars": [], "topic_id": 8600, "date_created": 1298523471.0696149, "message": "i have no idea how to create automatic behavior like that... as far as I understood, any functions I create inside a model are only called when I create/edit an entry. so even if I created a function inside the model to do that, it would rarely be called", "group_id": 81, "id": 195403}, {"user_id": 13817, "stars": [], "topic_id": 8600, "date_created": 1298523609.453795, "message": "You'd need some script running every x that updated all the records that have passed the date. James Bennett has a pretty good post on how to create standalone Django scripts http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/", "group_id": 81, "id": 195425}, {"user_id": 1736, "stars": [], "topic_id": 8600, "date_created": 1298523908.0462301, "message": "More specifically use a timed task.", "group_id": 81, "id": 195458}, {"user_id": 14492, "stars": [], "topic_id": 8600, "date_created": 1298523938.0267479, "message": "thank you", "group_id": 81, "id": 195460}, {"user_id": 13597, "stars": [], "topic_id": 8600, "date_created": 1298547575.7602019, "message": "If you've got Celery installed already, celerybeat is good at doing 'cron'-type stuff. Keeps tasks in python without having to mess with system cron.", "group_id": 81, "id": 196866}, {"user_id": 8364, "stars": [], "topic_id": 8600, "date_created": 1298567948.1304691, "message": "Use a pre_save signal (http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.pre_save) or a database trigger. The database trigger is going to be more reliable, and much more reliable and faster than the other methods mentioned here. However, it depends on your database providing those features.", "group_id": 81, "id": 199242}, {"user_id": 1736, "stars": [], "topic_id": 8600, "date_created": 1298569694.0989931, "message": "@spookylukey A pre-save hook would only work if the model is re-saved after the appropriate time. I don't know of any DBs that offer this kind of time-based hook.", "group_id": 81, "id": 199492}, {"user_id": 6894, "stars": [{"date_created": 1298600019.7134931, "user_id": 6587}], "topic_id": 8600, "date_created": 1298579744.7676909, "message": "I would usually avoid this sort of denormalization since it's a lot of complexity and probably won't result in significant performance gains anyway. Instead I'd make `active` a property rather than a db field, and use a manager method to get the active instances. Something like this: https://gist.github.com/842832", "group_id": 81, "id": 201843}, {"user_id": 8364, "stars": [], "topic_id": 8600, "date_created": 1298586325.6193061, "message": "@coderanger - ah, sorry, misunderstood the original request", "group_id": 81, "id": 202958}, {"user_id": 14492, "stars": [], "topic_id": 8600, "date_created": 1298606774.916115, "message": "but what I would also like to add, is the possibility of auto-updating the Active value based on an Expiration Date (so, sometimes, I might have no missions active). obviously I don't want to change the status manually, so I need some automation to check, from time to time, if the objects date_exp < datetime.now", "group_id": 81, "id": 205718}, {"user_id": 6894, "stars": [], "topic_id": 8600, "date_created": 1298606443.2120061, "message": "@gcmartinelli with that code i pasted, the `active` attribute isn't stored in the database, just calculated every time you access `foo.active`. So it doesn't need to get updated", "group_id": 81, "id": 205685}, {"user_id": 14492, "stars": [], "topic_id": 8600, "date_created": 1298606011.8081629, "message": "@craigds i ended up trying something like that, but when would the 'state' of the objects be updated? only when I search for it? or would it update when I search for any object?", "group_id": 81, "id": 205602}, {"user_id": 14492, "stars": [], "topic_id": 8600, "date_created": 1298606684.8597319, "message": "maybe if i explain better what i'm trying to achieve. my app will have Missions. Only one mission can be active at a given time... so I created an 'active' boolean field in the DB. When I save a new mission and activate it, the previous active mission is set to False.", "group_id": 81, "id": 205715}, {"user_id": 14492, "stars": [], "topic_id": 8600, "date_created": 1298606618.460511, "message": "@craigds but that involves a search (and calculation) inside the entire DB, doesn't it? isn't it better to store de 'active' value? (i'm a noob and reading about properties right now. sorry if my doubts are too obvious or make no sense)", "group_id": 81, "id": 205709}, {"user_id": 14492, "stars": [], "topic_id": 8600, "date_created": 1298607079.360431, "message": "btw, for future reference, found a good tutorial about django properties: http://www.b-list.org/weblog/2006/aug/18/django-tips-using-properties-models-and-managers/", "group_id": 81, "id": 205745}, {"user_id": 6396, "stars": [], "topic_id": 8600, "date_created": 1298639462.45312, "message": "This link may be helpful: http://www.ibm.com/developerworks/opensource/library/os-django-models/index.html", "group_id": 81, "id": 207693}, {"user_id": 6396, "stars": [], "topic_id": 8600, "date_created": 1298639280.7498579, "message": "Sounds like this would be better sorted by a custom model manager.", "group_id": 81, "id": 207681}]