|
nbv4 posted:since we're talking about extra, does anyone know why this doesn't work? You shouldn't be quoting "day", it's an alias not a DB column.
|
# ? Nov 10, 2009 01:51 |
|
|
# ? Jun 3, 2024 23:45 |
|
king_kilr posted:You shouldn't be quoting "day", it's an alias not a DB column. Now I get this: code:
|
# ? Nov 10, 2009 02:16 |
|
You may need to reiterate the exacty clause in the where section: total - night > %s my SQL is pretty rusty
|
# ? Nov 10, 2009 02:36 |
|
Yup, can't use column aliases from the SELECT portion in the WHERE clause. http://old.nabble.com/Column-alias-in-where-clause--td18967124.html
|
# ? Nov 10, 2009 02:56 |
|
No Safe Word posted:Yup, can't use column aliases from the SELECT portion in the WHERE clause. yep that was it, good catch. Now I have another problem. I have a model called "Car". Each car object has one and only one User. Basically I'm trying to find the most common VIN that occurs in the database, across all users: code:
|
# ? Nov 15, 2009 05:38 |
|
You're probably looking for.code:
|
# ? Nov 15, 2009 05:42 |
|
king_kilr posted:You're probably looking for. ah yes thats it. The 'c' query was joining the drive table which was screwing things up
|
# ? Nov 15, 2009 06:55 |
|
Anyone else as excited as I am that Dreamhost officially supports Django now? I just set it up the other day and it was absurdly easy and seems to be pretty fast. Kinda funny considering I've set it up manually there with three different accounts in the past couple months, but Passenger WSGI seems much faster than FastCGI so I'm happy to redo it all.
|
# ? Nov 15, 2009 19:46 |
|
Does anyone know how I could limit the number of objects selected in a ManyToManyField? For example, I have a model with a ManyToManyField and filter_horizontal on that field in the admin page, and I'd like to supply it a number and have it throw an error if I try to add more than that number of objects from the box on the left to the box on the right.
|
# ? Nov 17, 2009 16:23 |
|
You'll need to provide a custom form with your own validation logic: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-custom-validation-to-the-admin
|
# ? Nov 17, 2009 17:19 |
|
How do get totals by year using the django ORM?code:
this works, but feels so wrong: code:
|
# ? Nov 18, 2009 04:46 |
|
That's pretty much what you have to do, time permitting for Django1.2 I'll be working on the ability to do Model.objects.values("timestamp__year"), but no promises.
|
# ? Nov 18, 2009 05:50 |
|
king_kilr posted:That's pretty much what you have to do, time permitting for Django1.2 I'll be working on the ability to do Model.objects.values("timestamp__year"), but no promises. also, why no django dose last week/this week?
|
# ? Nov 18, 2009 06:24 |
|
nbv4 posted:
We recorded both this, and last week. We're working on getting them up, I think last weeks should be going up tonight.
|
# ? Nov 18, 2009 06:27 |
|
code:
code:
With Django I started thinking ORMs were interesting, but now I need to be reminded why the concept doesn't cause more problems with obfuscation, indirection, and lock-in than it solves. The above code would be a bigger pain to port from the Django ORM to SQLAlchemy, just within Python, than from one database to another. And that's relevant because I see avoiding framework/library lock-in as important as database lock-in. Possibly more important, because I could see myself someday wanting a change from Django's ORM much sooner than I'd want a change from, say, PostgreSQL which is a much more mature and predictable product.
|
# ? Nov 18, 2009 08:59 |
|
So to be clear code is tied to the APIs you used to write it? Brilliant insight. I'd like my code not to be tied too much to one technology too, it should be painless for me to change all my Python into Haskell easily.
|
# ? Nov 18, 2009 15:56 |
|
I agree that the notion I might have to change databases for my project and should be able to do so without any reprogramming is silly. I've only had to do it a few times that I can recall, and even when the projects was hard-coded SQL, the changes were minor and mostly handled by search/replace. That's not why Django tries to obfuscate the DB, though. The point of a Django app is that I can write one for my site, and you can then take that module and drop it into your site seamlessly. It's not about flexibility so much as reusability. If you know for sure that your app is custom enough that you won't need to reuse it (or will need to make programming changes anyways if you do), then Django still offers the ability to hard-code your SQL.
|
# ? Nov 18, 2009 17:51 |
|
If you don't want to use the ORM, don't use it? I don't see why you'd complain about choosing to use it if you envisage getting rid of it, presumably because you think it's defective in some way. If you think that writing everything in pure SQL will be easier and lead to less lock-in, do so. I find the concept of framework portability pretty baffling in itself, since it's not something you'd consider to be an independent component of your software - each one having the same interface, but rather the entire structure it's built around. As king_kilr said, the framework is the API - it don't make sense to have an API for the API on the framework level, you just end up with another framework to be "locked in" to. That all said, would it be practical to make a generic interface to every different type of framework? chips fucked around with this message at 18:36 on Nov 18, 2009 |
# ? Nov 18, 2009 18:32 |
|
SlightlyMadman posted:That's not why Django tries to obfuscate the DB, though. The point of a Django app is that I can write one for my site, and you can then take that module and drop it into your site seamlessly. It's not about flexibility so much as reusability. That's not true. You can write a reusable app in Django, yes, but that's not why Django offers an ORM or why you build something in Django as opposed to web.py or CakePHP.
|
# ? Nov 18, 2009 18:55 |
|
MonkeyMaker posted:That's not true. You can write a reusable app in Django, yes, but that's not why Django offers an ORM or why you build something in Django as opposed to web.py or CakePHP. Cool I'm fairly new to Django so maybe I haven't quite grasped the reasons behind everything yet. Care to elucidate?
|
# ? Nov 18, 2009 20:00 |
|
You write reusable apps to make your life easier. If you can share it with the community, even better. I don't see it as the goal of Django development, though. As for using Django over web.py or CakePHP, perhaps you need more power than web.py (easily) provides or you don't want to use CakePHP. CakePHP seems to be a great framework but Mozilla is moving from it to Django for their addons site early next year, so there are obviously some areas where it lacks. Web.py powers quite a few sites but doesn't offer all the features that Django comes with out of the box. If you don't want to roll your own stack, Django is the smarter choice.
|
# ? Nov 18, 2009 22:41 |
|
Cool, I've never even looked seriously at the other options you mention (just briefly at CakePHP which struck me as similar but Django seems to have a stronger community). I was more referring to the "that's not why Django offers an ORM" statement, though. I find the big advantage in of database independence to be that I can port my code from one project to another and not care that they use different databases. That seems like a far greater likelihood to me than the chances that I might suddenly decide to swap out my MySQL database for Oracle without wanting to change my code.
|
# ? Nov 18, 2009 23:37 |
|
When subclassing a non-abstract model, I know I can get the subclass instance from the superclass instance but I need to know its name. How do I get around that? I am new to django and web apps, so I have a feeling I am doing this wrong, but here is a fictional examplecode:
tehk fucked around with this message at 14:11 on Nov 19, 2009 |
# ? Nov 19, 2009 14:07 |
|
I'm trying to use Django's built in serializer object since I've just been directly calling simplejson forever but, I'm running into some quirks. I'm going to have a lot of views returning API information and am trying to follow from DRY concepts so I am writing a wrapper to handle the serialization and returning a proper HttpResponse. My problem is that I'm not always returning Django objects. Sometimes I'm just returning normal Python objects. The serializer will choke when it doesn't see Django's _meta tag. Is there a work around here? I'd like to use the Django serialization function since I'd like to support all the formats it supports (json, xml, yaml) ---- I'm feeling a little worn out right now so I'm probably explaining this horridly... So hopefully the code will speak for itself. Here is my current 'helper' module and an example implementation code:
code:
ATLbeer fucked around with this message at 20:21 on Nov 19, 2009 |
# ? Nov 19, 2009 19:50 |
|
tehk posted:When subclassing a non-abstract model [...] is there anyway to get the subclass without knowing its name? I know I could keep a list and just see if the variable is in instances namespace, but I figured something like this would have already been implemented. As I recall, somthing like this was talked about when ORM model inheritance was first proposed and implemented. It was rejected. Something to do with CORBA (of which I know nothing), I think. Only 'simple' solution I can think of is using mixins to store the class name, and its backed up by my finding example code here.
|
# ? Nov 19, 2009 21:06 |
|
Yay posted:As I recall, somthing like this was talked about when ORM model inheritance was first proposed and implemented. It was rejected. Something to do with CORBA (of which I know nothing), I think. code:
|
# ? Nov 19, 2009 23:23 |
|
Hey guys I was hoping one of you could lead me in the right direction to fixing this. code:
urls.py code:
code:
Thanks
|
# ? Nov 22, 2009 10:08 |
|
MEAT TREAT posted:logged_in_or_basicauth I grabbed from here: http://www.djangosnippets.org/snippets/243/ http://www.djangosnippets.org/snippets/243/ posted:Comments
|
# ? Nov 22, 2009 10:23 |
|
Thanks man I hadn't even noticed that all the other functions had the parenthesis and it was driving me nuts. Don't program at 3 in the morning.
|
# ? Nov 22, 2009 18:01 |
|
I've been using Django for over two years and template tags still drive me loving batty, especially when paired with forms. Can anyone comment on how the hell to encapsulate form processing logic so I don't need to write the same code all over my project? Group post here.
|
# ? Dec 4, 2009 15:36 |
|
What? Why would your form processing logic be anywhere near your template tags? Form processing logic is generally in your views.
|
# ? Dec 4, 2009 16:45 |
|
Elaborate, please. The form logic isn't specific to any view, so why would it live in one? Are you suggesting that I should duplicate form processing across all views that use the same form? Edit: Here is my template tag http://dpaste.com/129111/ I'd rather save myself the duplication and cheese the redirect. Surely there's a better way. Typh fucked around with this message at 18:35 on Dec 4, 2009 |
# ? Dec 4, 2009 17:22 |
|
Typh posted:Elaborate, please. The form logic isn't specific to any view, so why would it live in one? Are you suggesting that I should duplicate form processing across all views that use the same form? Form validation goes in forms.py. Form processing goes in views.py since you could want it processed differently depending on the 'location' of the save. Template tags are NOT the place for anything like this. If it's one form that's in multiple spots so you don't want multiple views for processing it, just make one and always direct it to that one. Forms/views from one app can hit views from another app just fine. The Django docs on forms are actually really good (until you get into formsets, then it's a little wanting). I'd give them another read if I was you.
|
# ? Dec 4, 2009 19:01 |
|
MonkeyMaker posted:Form validation goes in forms.py. Form processing goes in views.py since you could want it processed differently depending on the 'location' of the save. Template tags are NOT the place for anything like this. Which is something I don't have to do if I use a template tag. I understand "that's not what template tags are for", but the options presented otherwise do a much worse job of staying generic.
|
# ? Dec 4, 2009 19:17 |
|
Typh posted:But if I use a separate view for processing, what do I do when the form is invalid? I'd need to set up a way to return them back to the view they came from. If the form is invalid, it'll go back to the URL it was on already, that's how form validation works (at least how it's always worked for me). Also, note that I said form, not save. Those are two separate points of failure. Saying "it's not generic enough" isn't an excuse for doing it an amazingly wrong way, though. You could pass the current URL along with the form, so you always have the URL to reverse to get the view to render. There are always options.
|
# ? Dec 4, 2009 20:09 |
|
Form validation doesn't automatically go back to the URL you came from. Usually you call it from the view that loaded it originally anyways, and since you haven't redirected, that's where you end up again. I'm not making excuses to justify doing it the wrong way, I'm looking for pieces I might be missing to do it cleanly the "right" way. The URL isn't enough info because I need the objects from the original view to populate the form. Which as far as I can tell leaves me to stuff them in the form or session, which is pretty lame. I'm trying now to call the form processing view from my original view. Not ideal, but will hopefully cut the duplication down to a single line. Typh fucked around with this message at 20:36 on Dec 4, 2009 |
# ? Dec 4, 2009 20:33 |
|
Seems to me like the proper way to encapsulate the fact you have multiple functions wanting the same validation is to refactor the template tag into a separate function or class method, and have it called by all the varying object views. Its a supporting method, which is pretty much a definitive use case for either a helper function or a method inside a class object, non?
|
# ? Dec 4, 2009 23:57 |
|
I'm using the AuditTrail plugin to keep a detailed history of my model. I want to also know WHO made changes though, and in the Wiki in the Tracking Extra Information section, it mentions how I can have a parameter that calls a function to get extra information such as the current user. I cannot figure out how to get the current username though. The information is available for views in the request variable, but how can I access it form models.py? I really just need access to the username. The AuditTrail wiki certainly makes it sound like this should be a trivial thing to do but I cannot figure it out. EDIT: Hey, I figured it out. See here: http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser Is uses a middleware solution to make the User object from the request available anywhere. Works perfectly. Bitruder fucked around with this message at 00:03 on Dec 10, 2009 |
# ? Dec 9, 2009 23:26 |
|
Anyone currently using Django on Windows (or even Linux) with pyodbc, django-pyodbc, and SQL Server have any experience with lovely performance? I've been trying to figure out this problem for several days now, but I can't manage it. I created a barebones Django app to try and replicate the problem. If I don't involve the database at all, I get acceptable performance, roughly 400-500 requests/second according to Apache Bench. However, as soon as I involve the db, my performance drops to about 2-5 requests per second. Each individual query completes very quickly (less than a millisecond in some cases), but I still have horrid performance. I've tried with new tables with only one row, tables with 150,000+ rows, it doesn't matter at all. I'm currently using Django 1.1.1 (but I was using Django 1.1b0 with no difference) as well as the latest pyodbc and django-pyodbc (as well as the legacy django-pyodbc branch) with no differences at all. The problem exists even on CentOS with the same packages. I'm at my wits end here, I really need to solve this. We are 2 weeks behind deadline because of this problem. I will PayPal anyone that can offer a solution $100.
|
# ? Dec 14, 2009 20:59 |
|
|
# ? Jun 3, 2024 23:45 |
|
Your best bet is probably to hope in #django on freenode and message cramm, he's one of the developers of django-pyodbc and he can probably try to help.
|
# ? Dec 14, 2009 21:01 |