As far as not having to blow away your DB when you are playing around, you could use something like South. I find myself using the "iteratively working on a migration" workflow a lot when I'm playing around with things. You don't have to use that though, you could simply just make a little python script that creates all your data, so after you blow away your database you can just run your little "generate some data" script.
|
|
# ¿ Dec 6, 2013 05:09 |
|
|
# ¿ May 15, 2024 04:28 |
This logging thing is driving me mad. I don't even want to actually log SQL queries, I just want to know why it's not working. Added my logger: code:
code:
code:
When I hit my Django app through the webserver, however, nothing from django.db.backends gets written to the logs. If I change DEBUG=False to DEBUG=True in my settings, lots of stuff from django.db.backends gets written to the logs. I can't find anything that would suggest the logging is tied to that DEBUG setting though. edit: ughhhh how did I miss this: quote:For performance reasons, SQL logging is only enabled when settings.DEBUG is set to True, regardless of the logging level or handlers that are installed. fletcher fucked around with this message at 02:43 on Dec 19, 2013 |
|
# ¿ Dec 19, 2013 02:40 |
code:
|
|
# ¿ Dec 27, 2013 00:55 |
Dominoes posted:Anyone know how to run South? I did 'from south.db import db', and was greeted with "ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings." I've been using South but I've never had to manually write an import statement like that, all I ever do is: code:
Also, you can specify that environment variable at the top of your script (none of my migrations actually do this though): code:
|
|
# ¿ Jan 14, 2014 22:03 |
Dominoes posted:I was going off this Stack overflow thread I see, you want a data migration then. First create an empty data migration: code:
Then run the migration: code:
|
|
# ¿ Jan 14, 2014 22:33 |
Cool! Glad you got it working. My turn for a question - Is there a better way I should be doing something like this? I want it to handle the case where last_id might not be specified, or if it is, making sure it's the right data type. code:
|
|
# ¿ Jan 16, 2014 04:29 |
Megaman posted:Any ideas? What are you using to transfer the files from your django app server to S3?
|
|
# ¿ Jan 28, 2014 22:42 |
Megaman posted:Files are uploaded to the actual servers, then uploaded to s3. This seems like a step too many? Do people usually use forms to have users directly upload to s3 to get around using the servers? Then the issue is uuid/keys of said files. That sounds fine, your servers probably have to be the proxy to s3 to avoid cross domain security stuff. But what are you using to communicate with S3? If you eliminate the S3 step and just save them to your servers, does the upload still timeout?
|
|
# ¿ Jan 29, 2014 18:45 |
Megaman posted:Nope, the timeout happens between the server and s3. We also can't store on the server, we have tons of data, thus s3. I was thinking the client could upload from our app directly to s3, wouldn't that be a valid solution to this? We could just cut out the server. Wasn't suggesting it as a long term solution, just as a way to debug and isolate the issue. So for the third time...what are you using to transfer the files to S3?
|
|
# ¿ Jan 29, 2014 20:08 |
Megaman posted:Boto, but then again you're question is insanely vague so Boto, Python, S3, Django, Apache. One of those should answer your question however you meant to ask it. Yeah but just because Apache and Django are in your stack doesn't mean they are the components that send the files to s3. You also listed s3 in there...you're using s3 to send files to s3? That doesn't make any sense. Anyways, are you able to reproduce the issue with a tiny little python script that just uses Boto to send a file to s3? It looks like others have this issue too. The issue is for aws-cli but it uses boto under the covers.
|
|
# ¿ Jan 30, 2014 00:56 |
I've got a method on one of my models:code:
fletcher fucked around with this message at 03:30 on Feb 25, 2014 |
|
# ¿ Feb 25, 2014 03:27 |
MonkeyMaker posted:fletcher: Yup that is correct. I have no idea why the admin interface would be calling that method, I am certain the only caller of the method is a single spot in one of my templates. Even if it was using some sort of serializer, it wouldn't invoke my custom methods on models right? It's got me really stumped. The field is defined in my model as: code:
|
|
# ¿ Feb 25, 2014 18:46 |
I switched to DEBUG = True in the production clone environment, and viewing the admin page no longer increments that value. So I thought great, I can set DEBUG = False on my local dev server to debug...but I still can't reproduce it locally. edit: had the 2nd true/false backwards fletcher fucked around with this message at 19:31 on Feb 25, 2014 |
|
# ¿ Feb 25, 2014 19:03 |
MonkeyMaker posted:Wait, switching on DEBUG changed the way it acts? Yup, that appears to be the case, as strange as it may be. Unfortunately, I can't share the whole model and methods. Your question about the custom admin has got me thinking though - this one is an MPTT model, and that does custom admin stuff for rendering the hierarchy picklist options. I wonder if that's the culprit. Don't see any reference to the DEBUG setting in there, so doesn't really explain that behavior, but I'm gonna play around with it some more.
|
|
# ¿ Feb 25, 2014 22:27 |
Pollyanna posted:I'm at the point where I want to handle editing and deleting object models from the user side. I get how to create and read objects from the back-end, but is there a Django-ish way to edit and delete things from the front-end? Your CRUD operations (create, read, update, delete) always happen on the back-end. The only way for somebody to do it through the front should be via the back-end (). The Django way of doing this is through forms. It sounds like you may need two settings.py files, one that heroku will use, and one that you will use locally. My settings.py is all setup for the server to use, but at the bottom of it I have: code:
code:
I do not check in settings_local.py to source control or deploy it anywhere, it only needs to be used on my local machine. fletcher fucked around with this message at 22:44 on Feb 25, 2014 |
|
# ¿ Feb 25, 2014 22:34 |
NtotheTC posted:If I may sing the praises of Two Scoops of Django for a moment, they have a very good section on why you should avoid the settings_local.py anti pattern. (the short version is: unchecked-in code means it can be lost, also means all team members will have different settings_local.py files which leads to "It doesn't do that for me" errors that take hours to debug.) This seems like a great idea, but I guess I should mention the other piece of my puzzle: Chef. I already have all my environments defined in Chef (prod, testing, dev, etc), and they all use the same settings_local.py.erb template file. So while my settings_local.py doesn't come from the same repo as my django app, it does come from a central repo and all devs would have the same copy of it. Not saying this is a great setup, but that's why the settings_local.py pattern appealed to me in the first place.
|
|
# ¿ Feb 25, 2014 23:14 |
Currently I'm running collectstatic on each server the app is deployed on, and django-pipeline handles the less & uglifyjs and all that stuff. It can be kinda time consuming though, I was thinking I should do collectstatic on just 1 server, package it up, and then deploy the packaged version. How should I go about doing that?
fletcher fucked around with this message at 19:29 on Mar 11, 2014 |
|
# ¿ Mar 11, 2014 19:16 |
I wrote a python script for my Django app that is intended to be scheduled as a cron job. What folder should this file live in? Or should it be a Custom management command? edit: and a followup question since I think a custom admin command is the right answer: My admin command uses self.stdout.write, but it calls other methods that use logger.info('butts'). Can my custom admin command adjust the logger config so those messages are included if they are called by the admin command? fletcher fucked around with this message at 02:38 on Apr 1, 2014 |
|
# ¿ Apr 1, 2014 01:53 |
Awesome, thanks for the tip! Is there any way to get the test database to stick around after a failed run? I wanna poke around in the data to diagnose why it failed.
|
|
# ¿ Apr 2, 2014 20:08 |
From the Model.clean docs:quote:This method should be used to provide custom model validation, and to modify attributes on your model if desired. For instance, you could use it to automatically provide a value for a field So I've got: Python code:
code:
|
|
# ¿ Apr 5, 2014 01:00 |
Ahz posted:Does anyone know the best go-to library or whatever to generate custom QR codes? Out of curiosity, what do you want to use the QR codes for? I only ask because I've never seen somebody point their phone at one before. PNG (or even SVG?) would be a much better format for QR codes than GIF I would think. There seems to be no shortage of libraries for QR codes on PyPi: https://pypi.python.org/pypi/qrcode https://pypi.python.org/pypi/django-qrcode
|
|
# ¿ Apr 10, 2014 00:55 |
What does your logging config look like in Django? I have this in mine and it sends me an email with the full stack trace and all kinds of useful information if somebody hits a 500 error: code:
|
|
# ¿ Apr 15, 2014 23:03 |
Put it in your settings.py file
|
|
# ¿ Apr 16, 2014 00:04 |
Aw crap I thought it would be easy to send email on Heroku but apparently it's not, you have to use a third party SMTP provider: https://devcenter.heroku.com/articles/smtp Django can then be configured to use that third party SMTP server: https://docs.djangoproject.com/en/dev/topics/email/ So maybe not the route you want to go down right now if we're just trying to debug this 500 error. Regardless, to answer your logger functions in the views question, you don't have to do that stuff for the email alerts I was talking about. I'm actually not familiar with foreman at all, so not sure on that one. Sorry I think your solution is probably in the logging configuration though.
|
|
# ¿ Apr 16, 2014 00:40 |
Python code:
What goes in the question marks? How does generate_photo_filename know if it's handling profile_photo or cover_photo? I could just make separate functions for upload_to, wondering if there is a better way to handle this though. edit: and I suppose .jpg is just slightly more correct than .jpeg, but whatever we can ignore that for now fletcher fucked around with this message at 02:47 on Apr 17, 2014 |
|
# ¿ Apr 17, 2014 02:43 |
Is it necessary to make a South migration for something like python-social-auth? If you just do a pip install python-social-auth and then ./manage.py schemamigration social.apps.django_app.default --initial, I think the migration file ends up somewhere inside my virtualenv (and thus outside of my version controlled repo). So I'm thinking ./manage.py syncdb is sufficient, no need to use South?
|
|
# ¿ Apr 23, 2014 02:07 |
MonkeyMaker posted:Don't make migrations for software you don't control. Ok cool, thanks!
|
|
# ¿ Apr 23, 2014 17:36 |
supermikhail posted:Re-bruteforcing my way through Django: I have an (aforementioned) Entry, and a Rating which refers to an entry via ForeignKey. I've been working on getting the average of an entry's ratings after the user has voted (with jQuery). On the view side: Return the result of the Entry function that calculates the average as the HTTP result instead of returning all the ratings to calculate it client side
|
|
# ¿ Apr 26, 2014 23:03 |
I replaced django-openid-auth with python-social-auth and got confused when I started seeing exceptions like this:quote:ImproperlyConfigured: Error importing authentication backend django_openid_auth.auth.OpenIDBackend: "No module named django_openid_auth.auth" Couldn't figure out why it was still trying to use it even though there were no references to django_openid_auth in the code and then it hit me: it was probably storing it with the session. code:
|
|
# ¿ May 12, 2014 21:02 |
supermikhail posted:So now I intend to have javascript linked in the template it's used in. I'm a bit confused by the fact that I have to put load staticfiles every time, and also am wondering if this is the right way, because I haven't seen any recommendations re: arranging javascript files and it seems to be the usual practice to have everything in the same file. I think I'm remembering jQuery, in fact. It's not the most efficient way to go about it but I just use django-pipeline to combine & minify all javascript files into one single file, and that gets included in my base.html (which all other templates extend). While DEBUG=True they all get included as separate un-minified files. There's still a somewhat loose correlation between the names of some javascript files and the names of some templates, but it's not very strict and there's some overlap here and there.
|
|
# ¿ May 16, 2014 19:02 |
supermikhail posted:I don't see what the point of this is. Is it a performance boost if upon deployment everything is in a single file? Minimizing the number of HTTP requests is definitely something you can do to improve performance. There are tradeoffs though, since you don't want to load a ton of code that you aren't going to use. The site I do it on doesn't have a ton of JavaScript so it's not a huge deal. It keeps things simple though, I don't have to think about what JavaScript is loaded for which page, it's just all there all the time on every page.
|
|
# ¿ May 16, 2014 22:39 |
Is there a standard convention for where you declare all your signal handlers? edit: found this on the signals page https://docs.djangoproject.com/en/dev/topics/signals/ quote:Where should this code live? I'm using 1.5. In the end of my models.py do I just do an import myapp.signals or something? fletcher fucked around with this message at 23:29 on May 16, 2014 |
|
# ¿ May 16, 2014 22:45 |
Awesome! Thanks for the tips.
|
|
# ¿ May 17, 2014 09:26 |
Ahz posted:If this was a standard SQL recordset, I would make a single big query and pass back a large recordset with all the data I needed in a single obj so that I only hit the DB once. You can do that in Django as well through the use of select_related and prefetch_related. Just use those with your original query for the order and then you don't have to worry about your loops in templates generating additional queries.
|
|
# ¿ May 23, 2014 23:34 |
Should I be avoiding the use of auto_now and auto_now_add?
|
|
# ¿ May 29, 2014 00:41 |
MonkeyMaker posted:nope. I don't see any warnings or deprecations, do you? Yeah I figured it was probably ok. I was googling around and saw some people had pretty strong opinions about how they were evil and should be avoided, but the posts were quite a few years old. Aaaaand I just realized that I've had auto_now and auto_now_add backwards in all my field definitions this whole time
|
|
# ¿ May 29, 2014 01:07 |
Let's say I have a couple models: Blog and BlogComment. BlogComment has a ForeignKey to Blog. How to I use the ORM to find all the Blogs that have at least 1 comment? Or should I add a comment_count field to Blog and just filter on that?
|
|
# ¿ Jun 5, 2014 02:16 |
Haven't used annotate or Count yet. That's pretty sweet! Thanks Blinkz0rz!! Here's the SQL it generated: code:
|
|
# ¿ Jun 5, 2014 19:50 |
Is there a way to programatically set an ImageField to an existing local file and have it run through my upload_to override?
|
|
# ¿ Jun 6, 2014 19:34 |
|
|
# ¿ May 15, 2024 04:28 |
This seemed to work for me: http://stackoverflow.com/questions/3723220/how-do-you-convert-a-pil-image-to-a-django-file
|
|
# ¿ Jun 9, 2014 19:04 |