mirror of
https://github.com/not-kennethreitz/convore.json.git
synced 2026-06-21 15:40:58 +00:00
1 line
13 KiB
JSON
1 line
13 KiB
JSON
[{"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356191.3549211, "message": "so I want to determine how many Users are in a certain Mission", "group_id": 81, "id": 177419}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356126.6942599, "message": "no worries on the language barrier ;) your English is fantastic", "group_id": 81, "id": 177412}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356489.3792491, "message": "thank you", "group_id": 81, "id": 177462}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356522.6806259, "message": "def count_part(self):", "group_id": 81, "id": 177465}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356078.668529, "message": "hm.. english is not my main language... i believe i want to determine", "group_id": 81, "id": 177407}, {"user_id": 1736, "stars": [], "topic_id": 7975, "date_created": 1298356049.641768, "message": "If it is an OO-ish thing, putting it on the model (or a manager) is fine. Views in Django are generally pretty thin, with most \"view logic\" going in template tags.", "group_id": 81, "id": 177401}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356069.1331639, "message": "yeah! lovin'it", "group_id": 81, "id": 177406}, {"user_id": 1736, "stars": [], "topic_id": 7975, "date_created": 1298356326.8191259, "message": "on the mission you can do self.participations.all().count()", "group_id": 81, "id": 177440}, {"user_id": 1736, "stars": [], "topic_id": 7975, "date_created": 1298356329.5194011, "message": "to get the number", "group_id": 81, "id": 177441}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356334.198447, "message": "@coderange thanks!", "group_id": 81, "id": 177442}, {"user_id": 1736, "stars": [], "topic_id": 7975, "date_created": 1298356383.1567709, "message": "@gcmartinelli if you have a mission in the template, just {{ mission.participations.count }}", "group_id": 81, "id": 177450}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356401.03162, "message": "awesome!", "group_id": 81, "id": 177451}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356401.888, "message": ":)", "group_id": 81, "id": 177452}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356406.310463, "message": "thanks guys", "group_id": 81, "id": 177454}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298355920.9342439, "message": "so, from time to time I get myself thinking if I should be putting some functions on the View.py or Models.py", "group_id": 81, "id": 177398}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356013.0306871, "message": "for example... I want to define the number of participants in a certain group (models.Group). Should I put a function inside the model or should I just use it in the view?", "group_id": 81, "id": 177400}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356053.3066781, "message": "you want to define the number of participants in a certain group? or do you mean determine?", "group_id": 81, "id": 177402}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356056.4004121, "message": "wow, that was fast :)", "group_id": 81, "id": 177403}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356059.6530869, "message": ":)", "group_id": 81, "id": 177404}, {"user_id": 5778, "stars": [{"date_created": 1298356096.920825, "user_id": 14492}], "topic_id": 7975, "date_created": 1298356062.6225531, "message": "hooray for convore", "group_id": 81, "id": 177405}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356089.9114361, "message": "i want to \"count\"... lol", "group_id": 81, "id": 177408}, {"user_id": 1736, "stars": [], "topic_id": 7975, "date_created": 1298356124.2019091, "message": "Does Group just have an FK from its members?", "group_id": 81, "id": 177411}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356169.1906359, "message": "I have a model named \"Participation\" (horrible name), that pulls via FK a model named Mission and also the User model", "group_id": 81, "id": 177415}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356204.899164, "message": "i created a function inside my views.py:", "group_id": 81, "id": 177420}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356216.0566521, "message": "def count_part(mission):\n\tl = len(Participation.objects.filter(mission=mission))\n\treturn l", "group_id": 81, "id": 177421}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356221.952302, "message": "you could probably just use a simple ORM call for this", "group_id": 81, "id": 177422}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356223.388164, "message": "yes", "group_id": 81, "id": 177423}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356234.298063, "message": "Participation.objects.filter(mission=mission).count()", "group_id": 81, "id": 177425}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356235.534826, "message": "whats a ORM call? :s", "group_id": 81, "id": 177426}, {"user_id": 1736, "stars": [], "topic_id": 7975, "date_created": 1298356251.193517, "message": "Remember that all FKs automatically create a related manager on the other end", "group_id": 81, "id": 177428}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356255.8953111, "message": "whenever you use ObjectName.objects you're using Django's ORM", "group_id": 81, "id": 177430}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356262.0379181, "message": "oh, ok", "group_id": 81, "id": 177431}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356285.557832, "message": "but am i doing it right by using that code on Views and not on Models?", "group_id": 81, "id": 177435}, {"user_id": 1736, "stars": [], "topic_id": 7975, "date_created": 1298356285.9494679, "message": "so if your participation has \"mission = models.ForeignKey(Mission, related_name='missions')", "group_id": 81, "id": 177436}, {"user_id": 1736, "stars": [], "topic_id": 7975, "date_created": 1298356354.6660659, "message": "using len() on a queryset will fetch all the data. .count() just gets the number", "group_id": 81, "id": 177447}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356355.2627349, "message": "@codekoala how would I make a call for it on my view?", "group_id": 81, "id": 177448}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356110.0440149, "message": "and you only want to count the number of participants in a single group at a time?", "group_id": 81, "id": 177410}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356272.586493, "message": "or Object-Relational Mapper (I believe that's what it officially stands for)", "group_id": 81, "id": 177433}, {"user_id": 1736, "stars": [], "topic_id": 7975, "date_created": 1298356307.979547, "message": "er, make that related_name='participations'", "group_id": 81, "id": 177438}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356308.6703761, "message": "well, you could certainly make it a method in your model", "group_id": 81, "id": 177439}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356335.286231, "message": "you don't even need the all()", "group_id": 81, "id": 177443}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356353.066539, "message": "you can do a straight self.participations.count()", "group_id": 81, "id": 177446}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356427.064481, "message": "@gcmartinelli you probably don't need anything in the view unless you're doing some sort of math with the numbers", "group_id": 81, "id": 177457}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356443.522469, "message": "so @coderanger's suggestion is probably all you need :D", "group_id": 81, "id": 177460}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356488.9203351, "message": "yeah, you can rely on the automatic related_name, but it's often better to have it explicitly named", "group_id": 81, "id": 177461}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356512.4438889, "message": "inside my Participation model:", "group_id": 81, "id": 177464}, {"user_id": 1736, "stars": [{"date_created": 1298356548.1399021, "user_id": 5778}, {"date_created": 1298359902.3940451, "user_id": 214}], "topic_id": 7975, "date_created": 1298356542.642755, "message": "@gcmartinelli Use a pastebin for code, will be more readable", "group_id": 81, "id": 177467}, {"user_id": 5778, "stars": [], "topic_id": 7975, "date_created": 1298356557.0993929, "message": "gotta love those sites", "group_id": 81, "id": 177469}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356411.6310959, "message": "and kudos to Convore! :D", "group_id": 81, "id": 177455}, {"user_id": 1736, "stars": [{"date_created": 1298356454.7766171, "user_id": 5778}, {"date_created": 1298358860.691303, "user_id": 5582}, {"date_created": 1298359884.015451, "user_id": 214}], "topic_id": 7975, "date_created": 1298356432.835732, "message": "A good rule of thumb is to _always_ set related_name on your foreignkeys and manytomanys", "group_id": 81, "id": 177458}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356426.8854549, "message": "i'm impressed.... i'll be bugging you people alot now... lol", "group_id": 81, "id": 177456}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356501.6931019, "message": "so I would do something like:", "group_id": 81, "id": 177463}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356559.8938379, "message": "ok", "group_id": 81, "id": 177470}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356614.800704, "message": "guys, thank you so much", "group_id": 81, "id": 177473}, {"user_id": 14492, "stars": [], "topic_id": 7975, "date_created": 1298356627.4701271, "message": "i gotta go to sleep now.. 3:40am here :)", "group_id": 81, "id": 177475}, {"user_id": 5778, "stars": [{"date_created": 1298356678.462039, "user_id": 1736}, {"date_created": 1298359904.1808181, "user_id": 214}], "topic_id": 7975, "date_created": 1298356644.7093289, "message": "sleep well, and have fun with your project", "group_id": 81, "id": 177477}, {"user_id": 214, "stars": [{"date_created": 1298360257.8076789, "user_id": 5582}, {"date_created": 1298414148.3831971, "user_id": 1296}, {"date_created": 1298442161.1958079, "user_id": 14492}], "topic_id": 7975, "date_created": 1298360081.5181, "message": "To the original question: it depends whether the function/method is calculating/returning/doing something that's inherent to the domain model objects, or just munging data for a specific display purpose. If it's a part of the domain model, it should go on models; if it's just for display, it should go in the view or a template tag. One way to get at this question is to ask yourself, \"would I be likely to want this method if I were writing some command-line scripts that used these same model objects?\" If so, it should go on the model.", "group_id": 81, "id": 177623}, {"user_id": 214, "stars": [], "topic_id": 7975, "date_created": 1298361671.9226711, "message": "Or to approach it from the other end: if it has anything to do with markup or HTML or display formats, it should not be on the model.", "group_id": 81, "id": 177703}, {"user_id": 3354, "stars": [], "topic_id": 7975, "date_created": 1298363453.0659299, "message": "If there is a serious amount of shared logic (not strictly view, not strictly model) there is nothing wrong with adding lib.py files in the apps that use them. This is Python, after all, and putting libraries in modules is a time-honored technique.", "group_id": 81, "id": 177792}, {"user_id": 14309, "stars": [], "topic_id": 7975, "date_created": 1298374106.729749, "message": "for me, small functions like just retrieving objects go to views and complex logic like goes to models itself.", "group_id": 81, "id": 178543}, {"user_id": 3580, "stars": [], "topic_id": 7975, "date_created": 1298395055.656873, "message": "This may not be a popular answer, but I end up avoiding both in many cases. I've been putting functions like this in a services.py file in my apps. Putting too many functions on the models gets sticky eventually.. especially when they're update-related. Leads to confusion about whether the caller or the function will call save(), etc. I like to keep my view code very UI-centric.", "group_id": 81, "id": 180578}, {"user_id": 6471, "stars": [], "topic_id": 7975, "date_created": 1298593363.5038121, "message": "@phill the save() issue can be easily solved by copying Django's default behavior, so that the model methods have a save boolean argument.", "group_id": 81, "id": 204361}] |