|
ATLbeer posted:Something isn't right. Can you post one of your slow views? Your using the development server currently? MySQL is installed locally? What OS? Yea, using ./manage.py runserver with python 2.5.2, mysql is local, os is Arch Linux. It doesn't appear that there is any one thing that is dramatically increasing the page load time. There's quite alot of custom queryset code being used, and some model inheritance. I've pasted some of the things that are being called in the view here: http://pastebin.com/m653d303f (Tried to use privatepaste but I think I found some kind of security flaw). Mashi fucked around with this message at 17:06 on Mar 24, 2009 |
# ? Mar 24, 2009 17:03 |
|
|
# ? May 15, 2024 02:33 |
|
Mashi posted:Hmm.. I'd LOVE to be able to do this. In fact, it seems to make perfect sense to be able to make read only models that could use more complex queries in the backend while being more lightweight in Python, since alot of what I'm doing is trying to squeeze out flexibility from the Django ORM, which is going to load alot of objects for each model that I don't need if I'm only displaying data. Well, as king_kilr said, check out the new 'managed' option for models: http://docs.djangoproject.com/en/dev/ref/models/options/#managed It'll let you ensure that Django won't even try to update that particular DB table, meaning you can actually use SQL views and not worry about errors (which, prior to now, would crop up when you do e.g. manage.py syncdb -- it'd try to create or modify your SQL view, which of course would raise a database error). The feature is in trunk and I believe it'll be part of the 1.1 release; king_kilr pays closer attention than I do and can confirm/deny that.
|
# ? Mar 24, 2009 18:45 |
|
Yep, that's in the 1.1 beta now: http://docs.djangoproject.com/en/dev/releases/1.1-beta-1/
|
# ? Mar 24, 2009 19:32 |
|
bitprophet posted:Well, as king_kilr said, check out the new 'managed' option for models: Indeed, anything in trunk makes it's way into the release. The Django policy isn't to branch for a release after feature freeze, it's to wait until the the release is done before committing any new features.
|
# ? Mar 24, 2009 20:43 |
|
Searched through documentation and couldn't figure out how to do this. Here are the (pared down) tables that I'm using: I have a ModelForm based on the Consumption model, which works for users to add foods to their log. (I'm assigning User in views.py after they POST the form with User excluded, is there a better way to do this?) Then I want to display a food log summary with nutrient content for each food. I'm passing my_consumption = Consumption.objects.filter(user_id=request.user) into my template context, then looping through the objects within that and can pull everything I need from the related tables User, Measure, Food. I run into a problem with the Nutrient table. I have a whole gaggle of Nutrients, but only want to show a handful. The only way that I've found I can access the table is with a loop through consumption_item.measure.food.nutrient_set.all - but I can't filter that to only include Nutr_Def_id = 1 (for example). I want to do something like {{ consumption_item.measure.food.nutrient_set.(filter(id_Nutr_Def=1)) }}. Should I be passing another context to pull this information, or should I have my model set up differently?
|
# ? Mar 25, 2009 20:08 |
|
Write a template filter/tag to let you do simple operations on a queryset in the template will be the easiest way.
|
# ? Mar 25, 2009 20:20 |
|
Ansible posted:I have a ModelForm based on the Consumption model, which works for users to add foods to their log. (I'm assigning User in views.py after they POST the form with User excluded, is there a better way to do this?) Doing it like that is fine, there are a variety of ways to accomplish this. Another option would be to do this is by passing the user into the form, and overriding save to add the user in. Like so, code:
Ansible posted:I run into a problem with the Nutrient table. I have a whole gaggle of Nutrients, but only want to show a handful. The only way that I've found I can access the table is with a loop through consumption_item.measure.food.nutrient_set.all - but I can't filter that to only include Nutr_Def_id = 1 (for example). I want to do something like {{ consumption_item.measure.food.nutrient_set.(filter(id_Nutr_Def=1)) }}. I wouldn't do this in the template, filter the nutrients you want from the view, and pass it from the view to the template.
|
# ? Mar 25, 2009 22:00 |
|
Ansible posted:Here are the (pared down) tables that I'm using: This may be a stupid question, but what software did you use to make that diagram? My Google queries are proving useless.
|
# ? Mar 25, 2009 22:20 |
|
MetaKnyght posted:This may be a stupid question, but what software did you use to make that diagram? My Google queries are proving useless. It's a webapp and I freakin love it. Here is a hosted version but it's also very small and you can throw it on your own space pretty easily: http://ondras.zarovi.cz/sql/demo/ Thanks for the responses, I was hoping for a built in template function but I think that I see the way to do this via views - if not, i'll build out some templating
|
# ? Mar 25, 2009 23:23 |
|
Looks like a nice talk from Jacob Kaplan-Moss will be up from Pycon. "Real World Django" Slides are here: http://jacobian.org/speaking/2009/real-world-django/ Video / transcript coming.
|
# ? Mar 26, 2009 14:28 |
|
An odd problem: I'm using Django forms in another project due to two different websites (one Django, one Plone) needing the same forms and behaviour on each. (Long story involves connection to a common resource.) Well and fine, I'm happy with django.forms, I know how to use it, it's simple and well behaved but ... When you try to get the unicode / string version of an error from a Django form it calls a series of functions that move deep inside Django, look for the internationalization setting and end up trying to load the Django configuration file. Obviously this is no good for my "outside of Django" mode, so I overrode the rendering of the form to try and get the value of the error message directly. But, the errors are actually proxies that are lazily evaluated for whatever reason. (Translation?) And in some cases proxies containing proxies. These proxy objects are generated by the fields clean function This makes it hard to get at the actual value. Currently I'm calling "e._proxy____args[0]._proxy____args" which feels pecarious. Anyone got any other solutions or ideas? Things I've thought of: * Subclassing every field class I use to get it to create actual strings not proxies. Blergh. * Monkey patching the calling functions on the fields. Blergh. * Put a fake config file in the calling module and fooling the Django machinery into thinking this is the config file. Blergh.
|
# ? Mar 26, 2009 15:48 |
|
if the issue is not having a django settings file you can always do: from django.conf import settings settings.configure(MY_SETTING=value, OTHER_SETTING=value) To set up the right settings for there, because what you're seeing is django's internationalizating framework, you can probably coerce them to strings with just: settings.configure(USE_I18N=False)
|
# ? Mar 26, 2009 16:12 |
|
king_kilr posted:To set up the right settings for there, because what you're seeing is django's internationalizating framework, you can probably coerce them to strings with just: Thanks! That's 30 lines shorter than the solution I spent all morning on ...
|
# ? Mar 26, 2009 17:31 |
|
Back to my performance issue:code:
Dual core box, local mysql, Django dev server. EDIT: SOLUTION The problem turns out to be the Debug Toolbar itself! code:
Mashi fucked around with this message at 18:30 on Mar 26, 2009 |
# ? Mar 26, 2009 17:48 |
|
Not quite ready for the OP but, I want to share this with you all first just to get some feedback and some basic error checking. I'm looking to finish off these tutorials sometime this week and start a new thread for 1.0+ since the OP here is quite old. http://simpledjango.com/tutorial/
|
# ? Mar 30, 2009 19:52 |
|
ATLbeer posted:Not quite ready for the OP but, I want to share this with you all first just to get some feedback and some basic error checking. I'm looking to finish off these tutorials sometime this week and start a new thread for 1.0+ since the OP here is quite old. Otherwise thanks for the tutorial, I can't get enough of them being the Django newbie that I am
|
# ? Mar 30, 2009 20:45 |
|
geera posted:I've read through the first couple pages and it seems well enough, but there have been several grammar/spelling/punctuation issues. Just figured you'd want to know so you can polish it up a bit. That sounds like my writing Yeah, there will probably wind up being about 12 sections in total. They I'm going to fill in some of the Quick Reference material. This blog isn't meant to replace the formal documentation but, merely augment. It's just going to show a basic tutorial and some normal design patterns for application development
|
# ? Mar 30, 2009 20:51 |
|
ATLbeer posted:This blog isn't meant to replace the formal documentation but, merely augment. It's just going to show a basic tutorial and some normal design patterns for application development For example, is it best to create an application just for the site's content? So the index of https://www.mysite.com maps to an app in /mysite/main or /mysite/core, which handles serving the whole site? That seems a bit hamfisted, but I haven't seen that properly explained anywhere yet.
|
# ? Mar 30, 2009 21:32 |
|
Anyone here have experience implementing a graphing systems in a Django app? I am curious if there is an existing API that is solid, or if I should try to hook into one of Google's widgets. To continue my previous example, I record calories on a daily basis. I then want to graph that over time with a trailing average, and be able to select the duration then update through AJAX. Most graphs that I see look good-awful, or are done in flash. I've also considered throwing this on Google's App Engine, would that make it easier to link to their widget APIs? I absolutely love their graphing tools, even though most are done in flash. I've never worked with piping data to a flash applet though (but i've never played with python either soo)
|
# ? Mar 31, 2009 00:09 |
|
Ansible posted:Anyone here have experience implementing a graphing systems in a Django app? I am curious if there is an existing API that is solid, or if I should try to hook into one of Google's widgets. I'm currently using the google chart API, but if that isn't pretty enough then I'm sure a python library that uses GD to make pretty charts exists if you do a little googling.
|
# ? Mar 31, 2009 00:52 |
|
Ansible posted:Anyone here have experience implementing a graphing systems in a Django app? I am curious if there is an existing API that is solid, or if I should try to hook into one of Google's widgets. I've been building a JS charting thing using the OpenLayers mapping library, and it has worked out better than I had expected. It is a ridiculous way of doing it though. I was using the jQuery library flot for a while, and it's great. Easy to use, and the API is simple enough.
|
# ? Mar 31, 2009 07:06 |
|
slobodan posted:I was using the jQuery library flot for a while, and it's great. Easy to use, and the API is simple enough. Flot's the way to go. I tried using Google's Visualization API's but, honestly it's really a mess. I found their methodology to graph construction to to be a bit cumbersome and not intuitive. Flot rocked. I pointed Flot to a URI that spit out JSON and it made a graph and it rocked
|
# ? Mar 31, 2009 16:05 |
|
geera posted:I would be interested in seeing your sections on design patterns for Django applications. It seems like every tutorial focuses on creating a certain type of application, usually a blog, but doesn't really give best practices for just using Django to develop a regular web site with content that isn't based around articles or blog posts or whatever. Some tutorials featuring topics such as these would kick rear end. Please do this. Also, mathplotlib?
|
# ? Apr 1, 2009 18:29 |
|
Just got my current project using flot instead of google chart API and flot looks so much nicer and has all the fancy rollover stuff built in. Great recommendation.
|
# ? Apr 1, 2009 20:02 |
|
Mulozon Empuri posted:Some tutorials featuring topics such as these would kick rear end. Please do this. I agree. Is there a good source for best practices in django development? My entire site is just one app, but I'm considering splitting it up into functional areas based on related tables/models. Flot looks pretty cool, I'll play with that over the weekend.
|
# ? Apr 1, 2009 20:06 |
|
Ansible posted:I agree. Is there a good source for best practices in django development? My entire site is just one app, but I'm considering splitting it up into functional areas based on related tables/models. Read anything james bennet writes(see his DjangoCon video on youtube on reusable applications) his look, Practical Django Development is also good.
|
# ? Apr 1, 2009 20:39 |
|
I'm planning on creating a new google appengine project soon that will create web pages with artwork determined by user input (basically bezier curves showing relationships). The best method I've come up with is to use SVGs since I want them to scale correctly. I would use in-line SVG code in xhtml, but in-line svg isn't fully supported by all browsers (safari seems to put 100pixel margins at the bottom of any inline svg code). So instead I'm planning on using object= and embed= code, however this means I must create the files before sending. If I can't access the file system on app engine, how can I do this? I'm just doing theory right now, so the short version is, how do I dynamically create files to send to users without doing anything to the file system?
|
# ? Apr 5, 2009 07:04 |
|
politicorific posted:I'm planning on creating a new google appengine project soon that will create web pages with artwork determined by user input (basically bezier curves showing relationships). The best method I've come up with is to use SVGs since I want them to scale correctly. I would use in-line SVG code in xhtml, but in-line svg isn't fully supported by all browsers (safari seems to put 100pixel margins at the bottom of any inline svg code). So instead I'm planning on using object= and embed= code, however this means I must create the files before sending. If I can't access the file system on app engine, how can I do this? I don't know exactly how to do this in Django, but the basic idea (I think) is you'd have a view that spews out the SVG, then get Django to write the headers as if you're sending an SVG (because you are). (That's the part I'm not sure about in Django.) Then, in the template where the SVG is to appear, point it to the right URL for the aforementioned view.
|
# ? Apr 5, 2009 13:02 |
|
pokeyman posted:I don't know exactly how to do this in Django, but the basic idea (I think) is you'd have a view that spews out the SVG, then get Django to write the headers as if you're sending an SVG (because you are). (That's the part I'm not sure about in Django.) Then, in the template where the SVG is to appear, point it to the right URL for the aforementioned view. This is correct. Headers are stupid easy, just use dictionary syntax on a response object. Here's an off-the-top-of-my-head, these-are-probably-not-the-right-headers example: code:
|
# ? Apr 5, 2009 13:30 |
|
Anyone have a preferred method for storing additional profile data against users? Using a user profile makes the account creation / editing forms a bit messy. Anyone had success subclassing User, or know a nice way to do the forms for a User with a custom profile?
|
# ? Apr 7, 2009 16:33 |
|
Mashi posted:Anyone have a preferred method for storing additional profile data against users? Using a user profile makes the account creation / editing forms a bit messy. Anyone had success subclassing User, or know a nice way to do the forms for a User with a custom profile? Just use a user profile model, that's how it's done. Needing to hook up a signal reciever and handle 2 ModelForm's isn't difficult, it's like 10 lines of code.
|
# ? Apr 7, 2009 17:24 |
|
king_kilr posted:Just use a user profile model, that's how it's done. Needing to hook up a signal reciever and handle 2 ModelForm's isn't difficult, it's like 10 lines of code. Man if only we had an example
|
# ? Apr 7, 2009 17:50 |
|
m0nk3yz posted:Man if only we had an example http://sam.bluwiki.com/blog/2008/05/extending-user-model-profiles-in-django.php code:
code:
http://docs.djangoproject.com/en/dev/topics/signals/
|
# ? Apr 7, 2009 18:25 |
|
m0nk3yz posted:Man if only we had an example Yes, if only
|
# ? Apr 7, 2009 19:02 |
|
Try Pinax, it's got user profile stuff built in and I think makes it easier. It's also great for adding any kind of community functionality to your site.
|
# ? Apr 7, 2009 23:55 |
|
Ok ignore everything below, after spending hours googling, I'm apparently a spaztard, because 'django file uploads' tells me exactly what I needed to know, I needed to pass in request.FILES and POST. you win, Internet. So I'm trying to get to grips with Django -- I've got a bit of python experience behind me (fiddling with cherrypy, and qt) -- but I'm hitting a weird stumbling block with models and forms. I've got a model like so: code:
code:
The view I'm working with is like so: code:
Can anyone shed some light on how to handle this? without file fields, this process works fine, hence my suspicisons about request.POST Yay fucked around with this message at 14:05 on Apr 8, 2009 |
# ? Apr 8, 2009 13:57 |
|
Yay posted:Ok ignore everything below, after spending hours googling, I'm apparently a spaztard, because 'django file uploads' tells me exactly what I needed to know, I needed to pass in request.FILES and POST. you win, Internet. Don't worry. I can't tell you the number of times I've reinvented the wheel in Django and in Python. When I have a something I'm looking for a solution now the first thing I do is browse through the Python docs for a few minutes then browse the Django docs. Usually something new will stick out at me and usually lead me to a solution and make me learn a new module or builtin
|
# ? Apr 8, 2009 14:45 |
|
I'll save the next guy some time and put in a reminder to make sure you have enctype set on your <form> tags.
|
# ? Apr 8, 2009 16:16 |
|
I've been using the admin site and I broke something in one of the models. Now, when I click on a row to view it in detail, I get this error: code:
code:
Here is the table it is trying to view: code:
code:
Anyone see anything?
|
# ? Apr 10, 2009 08:55 |
|
|
# ? May 15, 2024 02:33 |
|
code:
|
# ? Apr 10, 2009 14:28 |