|
fletcher posted:From the Model.clean docs: Model.clean() is kind of a lovely little snippet. It only gets called by ModelForm.clean() and, even then, isn't super-reliable. If you want to custom calculate a field on a model, do it in the save() method.
|
# ? Apr 5, 2014 01:36 |
|
|
# ? Jun 3, 2024 18:48 |
|
Django friends itt: what is best in life, Django or Python-Twisted? I've never Django'd before.
|
# ? Apr 6, 2014 17:33 |
|
They do different things. Ones for doing async web server while django is a framework for creating websites. Django uses at a lower level a web server to handle requests but mostly that sort of stuff is abstracted away from a django user. The best way to get a hang of what I mean is to go and do the poll tutorial on the django website. But yea django is best in life but so is python-twisted and;
|
# ? Apr 7, 2014 20:56 |
|
okay, so if I didn't really want to get heavy into async web stuff which I did on my job, for a personal website, I should maybe use Django?
|
# ? Apr 7, 2014 23:45 |
|
Smarmy Coworker posted:okay, so if I didn't really want to get heavy into async web stuff which I did on my job, for a personal website, I should maybe use Django? If it needs a database, sure.
|
# ? Apr 7, 2014 23:52 |
|
golden
|
# ? Apr 8, 2014 19:07 |
|
Hey folks, I'm having a weird issue that I was hoping for some help with. I have a model with clean() and validate_unique(). When the model is invalid I raise a ValidationError in these methods as per the documentation. However, when I create a model that's invalid from the admin panel, I get code:
Does anyone know how to resolve this issue?
|
# ? Apr 8, 2014 19:29 |
|
MonkeyMaker posted:Model.clean() is kind of a lovely little snippet. It only gets called by ModelForm.clean() and, even then, isn't super-reliable. As someone who does call full_clean mostly, I'd be keen to know in what way you're suggesting it's not reliable, as it's not something I've ever knowingly come across. * actually, model validation is also lovely because it has a different API to forms. An API which has remained stable and flexible for ... 7 versions?
|
# ? Apr 9, 2014 17:55 |
|
Does anyone know the best go-to library or whatever to generate custom QR codes? I'm looking to generate and then store the GIF or whatever they create as a binary in postgres.
|
# ? Apr 10, 2014 00:32 |
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 |
|
Yeah I found those libraries, they seem to work fine, thanks. They're a bit of a fad, but I don't think they're going away and only going to become more ubiquitous as they become a more accepted standard for mobile input. Ironically in my quest to find a good qrcode generating library for python, I decided to just do QR generation on the fly on iOS/Android itself instead of server-side.
|
# ? Apr 10, 2014 03:17 |
|
Yay posted:* actually, model validation is also lovely because it has a different API to forms. An API which has remained stable and flexible for ... 7 versions? Yeah, what's the deal with this? You'd think more effort would be put into something that promotes DRY principles. Basically I don't want to write separate form validation for my admin form and my application form and the fact that it's like pulling teeth is frustrating to say the least.
|
# ? Apr 10, 2014 12:01 |
|
Blinkz0rz posted:Yeah, what's the deal with this? You'd think more effort would be put into something that promotes DRY principles. Just make your Model.save() check for Model.clean() before it saves, obv. (I've, sadly, done that before) --- Also, I gave a tutorial yesterday at PyCon (if you're here, say hi). If any of you want the book I wrote for it, it's here as a PDF or here as HTML
|
# ? Apr 10, 2014 15:33 |
|
MonkeyMaker posted:Just make your Model.save() check for Model.clean() before it saves, obv. To be honest, the issue I'm running into is raising multiple ValidationError exceptions from the model.clean() and model.validate_unique() methods. You'd think the error dictionary would work correctly, but it seems like there's a minor difference in the way the model instance is handled when it's being returned from model validation versus form validation. Any thoughts on how to handle that? I was thinking I could write stubs for the form that implement full_clean() and then handle the exceptions when they bubble up, but I really do want to adhere to DRY.
|
# ? Apr 10, 2014 20:50 |
|
MonkeyMaker posted:Just make your Model.save() check for Model.clean() before it saves, obv. I'm at Pycon! I'll say hello awkwardly if I see you.
|
# ? Apr 11, 2014 00:46 |
|
more like dICK posted:I'm at Pycon! I'll say hello awkwardly if I see you. I'll be in the board game open space this evening. Come by! blinkz0rz posted:To be honest, the issue I'm running into is raising multiple ValidationError exceptions from the model.clean() and model.validate_unique() methods. Not really. I don't think I've ever really used Model.validate_unique(). There isn't a model instance being returned from form validation, though. It's actually a ModelForm instance which is "saved" before the model is written to the db itself. It's a weird process but seems to work.
|
# ? Apr 12, 2014 20:07 |
|
I ended up moving my uniqueness test (Model.validate_unique()) into clean() even though the docs say I should separate them. Everything works now. Weird that raising multiple ValidationError exceptions in separate validation methods would blow up so spectacularly.
|
# ? Apr 13, 2014 01:38 |
|
If you missed PyCon 2014 (or just the tutorials or whatever), lots of the videos are online. Two of the Django tutorials: Django for Web Designers and Front End Developers by Tracy Osborn Getting Started with Django: A Crash Course by me.
|
# ? Apr 14, 2014 12:53 |
|
I'm going to cry. How do I get a traceback in Foreman/Heroku logs for Django? I'm getting a Server Error 500 in Foreman when everything works perfectly on a local server. I can't figure out why it's breaking without knowing what's erroring out. Unfortunately, all I get from Foreman is: code:
code:
|
# ? Apr 15, 2014 22:54 |
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 |
|
Um, I don't. How do I use that?
|
# ? Apr 15, 2014 23:54 |
Put it in your settings.py file
|
|
# ? Apr 16, 2014 00:04 |
|
So this sends you an email, correct? The documentation mentions something about adding logger functions to the views. Do I need to include that as well, or does Django automatically handle stacktraces and email them? Also, I assume it won't send an email from Foreman, and only off of the herokuapp server?
|
# ? Apr 16, 2014 00:16 |
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 |
|
Don't worry about it, I figured I can store the log as a file. I managed to track it down to a South fuckup I ended up wiping the database and starting over, but hooray, it works! Thanks a bunch.
|
# ? Apr 16, 2014 01:06 |
|
FYI, it's really easy to set up django send grid on heroku to send emails. Just google it and you'll be running all quick like.
|
# ? Apr 16, 2014 04:05 |
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 |
|
fletcher posted:wondering if there is a better way to handle this though I've not used it but this is what I would do: https://github.com/iserko/django-storages/blob/master/storages/backends/image.py You can use custom storage objects like: Python code:
raymond fucked around with this message at 16:01 on Apr 17, 2014 |
# ? Apr 17, 2014 08:19 |
|
What's the best way to create this setup: Entry - rating - User? Entry has ratings, User also has ratings that s/he has made of entries. (Also should I extend the base User class?) Currently I have a Rating class that has User and Entry as ForeignKeys, but I'm not sure how to handle Entry. Should it have a ManyToManyField "ratings" variable (even though a Rating can belong only to one Entry)? Also each Rating object can be made only by a single User. I'm sure this stuff is handled daily by experienced coders, so how? (The purpose of the arrangement is obviously to ensure that one user gets one vote/rating.)
|
# ? Apr 20, 2014 20:13 |
|
Each Rating belongs to one User and to one Entry, I suppose? Each Entry and each User can Have Many Ratings, but each Rating has one associated Entry and one associated User. So the Rating would have a Foreign Key to a user and a Foreign Key to an Entry, and both Entries and Users have one-to-many fields for Ratings.
|
# ? Apr 20, 2014 21:01 |
|
I didn't see a one-to-many field in Django documentation, and was rather saddened by it. Or am I missing something?
|
# ? Apr 20, 2014 22:42 |
|
supermikhail posted:I didn't see a one-to-many field in Django documentation, and was rather saddened by it. Or am I missing something? django.db.models.ForeignKey()
|
# ? Apr 21, 2014 01:19 |
|
I don't get it. It says it's many-to-one, not the other way around, and my google-fu suggest they are not the same... Okay, I've managed to dig up the fact that there is a "Related objects' manager", which ensures that a ForeignKey relationship gets "two-way traffic". I didn't realize that but the fact that the tutorial's "question" had access to "choice_set" was a bit suspicious. Thanks for making me stare in the right direction for long enough!
|
# ? Apr 21, 2014 02:01 |
|
You're own structure is a many-to-many structure, a real one, not the hacky thing Django calls its own one. You're right, you use the related manager to traverse the reverse relationship. I prefer to use the 'related_name' attr to make traversal a little more obvious when coding rather than the default *_set.
|
# ? Apr 21, 2014 04:43 |
|
Is there an easy way to do periodic tasks in Django that doesn't involve Celery and works on Python 3.3+? I'll use Celery if that's what it comes down to, I'm just a bit sick of janitoring init scripts.
|
# ? Apr 23, 2014 00:41 |
|
more like dICK posted:Is there an easy way to do periodic tasks in Django that doesn't involve Celery and works on Python 3.3+? I'll use Celery if that's what it comes down to, I'm just a bit sick of janitoring init scripts. Have cron call a management command?
|
# ? Apr 23, 2014 00:53 |
|
Oh wow I totally forgot you can write custom manage.py commands. That simplifies things immensely.
|
# ? Apr 23, 2014 01:08 |
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 |
|
fletcher posted: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? Don't make migrations for software you don't control.
|
# ? Apr 23, 2014 17:11 |
|
|
# ? Jun 3, 2024 18:48 |
MonkeyMaker posted:Don't make migrations for software you don't control. Ok cool, thanks!
|
|
# ? Apr 23, 2014 17:36 |