|
I'm trying to make a "shopping cart" that will list out several objects that have been saved in session. So far I've been able to use form.Form, formset and formset_factory to output a list of forms. I'm looping through my session to make up "initial_data" for the formset. I have "custom made" the form because I don't want the widgets that a model form would output, and I only need 1 of the fields from the model (quantity = forms.IntegerField(required = True) is all I need) My issue is that I don't know of anyway of dynamically setting the label for one of the fields, and I'd like to also output of a model's method in each form. I could do a integerField for the method output, but I'd have to set it as read-only and the widget just looks wrong. Ideally I'd like something like this for the inital_data {'quantity': {'label='object.name', 'value'='2'}, 'cost': object.cost()} So that it outputs like this (qty is the only field I want editable) Mac & Cheese Qty:[ 2 ] $5.00 Pickles Qty:[ 4 ] $12.00 ...etc Right now all I get is Quantity [ 2 ] Quantity [ 4 ] I've thought about just looping through formset and each form and doing the form 'by hand' and doing a dict of labels and costs that would correspond to each quantity field, but I can't wrap my head around how that would line up based on how formset names the forms. I've also thought about doing "my own" formset by just making a dict considing of a form, label, and cost, but I can't wrap my head around how I would validate those forms on POST. Any ideas or advice is much appreciated, and apologies if this has been asked before in this thread BREAKING NEWS: I solved my own problem. Using range(len(formset)) I looped through each form in the formset and made a list of dictionaries that were made up of formset[i] and session['objects][i] (they will match up because I looped through session['objects'] to create the 'initial_data' for the formset_factory) I passed this list of dicts to the template. Then, in the template instead of looping through {{form}} or {{formset}} I looped through the list of dictionaries, piecing together the form like {{formset}} generates. Anytime I needed something like "id_form-X-field" or 'label for=id_form-X-field'(where x is suppose to be the form #) I used "forloop.counter0" (which I just learned about ). It wasn't too easy, but wasn't too hard. I just kept getting lead down the wrong paths of "custom field" and "custom widget" Lagg fucked around with this message at 20:53 on May 16, 2011 |
# ? May 16, 2011 04:28 |
|
|
# ? Jun 5, 2024 08:46 |
|
I am trying to do a runserver on these Django files from the book Pratical Django to see if it's compatible with 1.3.0, which I'm not so sure about. When I try to run it, I get this:code:
|
# ? May 16, 2011 15:17 |
|
It means you don't have the django-coltrane app installed/on your PYTHONPATH, but you have it in INSTALLED_APPS in your settings.py file, so Django can't find it.
|
# ? May 16, 2011 19:20 |
|
wheezy360 posted:It means you don't have the django-coltrane app installed/on your PYTHONPATH, but you have it in INSTALLED_APPS in your settings.py file, so Django can't find it.
|
# ? May 16, 2011 19:37 |
|
This http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/ was published in 2006. Is a class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) still the best way to add fields to the User model?
|
# ? May 23, 2011 00:13 |
|
epswing posted:This http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/ was published in 2006. Is a class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) still the best way to add fields to the User model? The canonical way these days seems to be using django-profiles (written by the author of the blog post you linked)
|
# ? May 23, 2011 04:52 |
|
ufarn posted:What exactly is PYTHONPATH, and where can I find it? God I hate PYTHONPATH It's an environment variable that you can set. so pre:PYTHONPATH=/home/shithead/some_python_shit/ python To see what is currently in your path, do this pre:python >>> import sys >>> print sys.path pre:python >>> import sys >>> sys.path.append('/some/path')
|
# ? May 23, 2011 04:55 |
|
My friend ag3ntorang3 and I just launched djangopeople.me which is basically a replacement for djangopeople.net. Anyway, check out, let us know what you think, poo poo like that.
|
# ? Jun 1, 2011 02:13 |
|
MonkeyMaker posted:My friend ag3ntorang3 and I just launched djangopeople.me which is basically a replacement for djangopeople.net. Anyway, check out, let us know what you think, poo poo like that. The location-awareness is nice, but a little too specific. Would be nice to narrow down by City or something like that.
|
# ? Jun 2, 2011 02:06 |
|
Captain Capacitor posted:The location-awareness is nice, but a little too specific. Would be nice to narrow down by City or something like that. You can zoom in on the map when you set your location a LOT further than anyone else can when they view your profile, so they won't be camping outside your door or anything. We'll probably introduce some anonymizing abilities, too, to make it friendlier to you paranoid types
|
# ? Jun 2, 2011 07:19 |
|
Anyone have any ideas about how I could possibly go about converting a site from Drupal to Django-cms?
|
# ? Jun 2, 2011 12:29 |
|
Okay! I posted about this problem in the Python thread but it turns out it's a problem purely with Django. So far, as nice as Django is, I'm finding the community(at least in IRC) is full of dicks. This is probably a really easy problem to get over, but I can't figure it out all the same. I'm getting a constant error whenever I try to log in with any user, 'User' object has no attribute 'backend'. Or, you can replace 'User' with 'AnonymousUser'. This depends on whether I've logged into the admin panel or not. Regardless- for some reason, my Authenticate calls are going through fine without error(as far as I can tell), but no Backend is being set... ever. What could possibly cause this? As for showing off code, here you go: code:
Edit: I should note, a lot of what you're seeing there is a part of Python-Oauth2. In fact, nearly this entire piece is a straight lift from how they're supposed to do the Django implementation, as detailed on the site there. quaunaut fucked around with this message at 16:13 on Jun 6, 2011 |
# ? Jun 6, 2011 16:02 |
|
What exactly are you trying to do? Are you trying to let people authenticate using Twitter instead of a built in username/password?
Profane Obituary! fucked around with this message at 14:13 on Jun 7, 2011 |
# ? Jun 7, 2011 14:05 |
|
Profane Obituary! posted:What exactly are you trying to do? Are you trying to let people authenticate using Twitter instead of a built in username/password? Yep.
|
# ? Jun 7, 2011 17:09 |
|
Best way to do Twitter auth that I've found yet: django-social-auth. It's what we used on djangopeople.me and it's amazingly simple.
|
# ? Jun 7, 2011 17:16 |
|
MonkeyMaker posted:Best way to do Twitter auth that I've found yet: django-social-auth. It's what we used on djangopeople.me and it's amazingly simple. I don't think I'd be able to use any existing python twitter libraries, would I? At least, not in that implementation? Edit: lol. It's built off of the same library as what I'm working out of for oauth. So I bet I could easily use this for oauth then just flip it over to the twitter API when it's time to do poo poo! gently caress yeah. Gonna do more research here. quaunaut fucked around with this message at 01:28 on Jun 8, 2011 |
# ? Jun 7, 2011 23:16 |
|
quaunaut posted:I don't think I'd be able to use any existing python twitter libraries, would I? At least, not in that implementation? Existing libraries for what? Sending tweets? I used it with Tweepy with no problems. It's just for creating/validating the local accounts based on Twitter (Facebook, OAuth, etc) auth.
|
# ? Jun 8, 2011 17:15 |
|
Help me Django thread! I have a work order database. I need to find the average time it takes for a staff member to close their tickets on a weekly/monthly/yearly basis (relative to "now"). As it stands now, there's two columns in my database for storing this information: the ticket creation date and the ticket closing date. How would I go about doing something like this?
|
# ? Jun 9, 2011 17:55 |
|
root beer posted:Help me Django thread! Off the top of my head, something like: code:
|
# ? Jun 9, 2011 19:12 |
|
Yay posted:Off the top of my head, something like: Thanks a bunch.
|
# ? Jun 10, 2011 22:58 |
|
Anyone remember a blog post in the last month or so about an easy skeleton for starting up a new Django project? I'm trying to document the creation of a new site basically from easy_install virtualenv on out, and there was some blog post that covered a lot of it, I remember specifically that it mentioned pip's requirements.txt and creating the new virtualenv, but some google searches for it haven't turned it up. EDIT: Found it, it was http://www.mahdiyusuf.com/post/5282169518/beginners-guide-easy-install-pip-and-virtualenv Hughlander fucked around with this message at 21:02 on Jun 11, 2011 |
# ? Jun 11, 2011 18:18 |
|
Hughlander posted:Anyone remember a blog post in the last month or so about an easy skeleton for starting up a new Django project? FWIW here's my django app skeleton: https://github.com/technivore/django-app-skeleton. It's forked from Corey Oordt's original version with some minor changes that fit my style. I really like it because it fits the documentation-driven development method I've been using with pretty good success lately. But long story short, it will create the virtualenv for you; I think you might have to have virtualenvwrapper installed too though.
|
# ? Jun 12, 2011 02:19 |
|
Again, time to call upon the Django thread to save my job: In my work order system, my boss has asked for a way to be able to view a monthly breakdown of how many orders were created per month for any given year. I know that QuerySets have the ability to do things like pre:Order.objects.filter(created_on__year=2010) I have a couple ideas how to do it, but I'm betting there's some method for doing so hiding away that I have no clue about that'd take hours of coding and condense it into a couple lines.
|
# ? Jun 13, 2011 23:22 |
|
root beer posted:Again, time to call upon the Django thread to save my job: You've got the QuerySet for a given year, and you can filter it further to get QuerySets for each month, or use count() if you just need the number of orders. code:
e: I think you just solved one of my own Django problems by having me reread the official documentation 205b fucked around with this message at 08:23 on Jun 14, 2011 |
# ? Jun 14, 2011 08:16 |
|
root beer posted:Excellent, another case wherein Python takes something that seems complex and makes it stupidly simple. code:
code:
Vulture Culture fucked around with this message at 19:07 on Jun 14, 2011 |
# ? Jun 14, 2011 18:49 |
|
ninepints posted:You've got the QuerySet for a given year, and you can filter it further to get QuerySets for each month, or use count() if you just need the number of orders. Misogynist posted:That's just regular simple. Stupidly simple is, as Yay said, turning that loop into a list comprehension: I love Django. I've learned so much about so many different of facets of programming because of it.
|
# ? Jun 14, 2011 19:54 |
|
root beer posted:Thanks, that's what I figured I'd end up having to do. I'm just gonna have to try it and see for myself how many queries it runs. Simply because I love sharing random tidbits of Django goodness, if your Work order system needs any sort of async work done, look at Celery. I'm using it in the monitoring and stats system I'm writing and it integrates so very nicely.
|
# ? Jun 16, 2011 01:59 |
|
Captain Capacitor posted:Simply because I love sharing random tidbits of Django goodness, if your Work order system needs any sort of async work done, look at Celery. I'm using it in the monitoring and stats system I'm writing and it integrates so very nicely.
|
# ? Jun 16, 2011 03:15 |
|
Misogynist posted:I think we're writing the same monitoring system. A few factors: Control of repetitive tasks from a web frontend (allowing users to control how frequently stats are collected) Task chaining AMQP Integration Ease of distribution for multiple workers (Or in my case, EC2 instances)
|
# ? Jun 16, 2011 03:18 |
|
Captain Capacitor posted:I'm using Carbon and Whisper I'm currently experimenting with collectd + Carbon/Whisper/Graphite (+ Nagios) for a monitoring stack. It's pretty nice so far. Are you using Graphite at all or just the Carbon/Whisper components? If the latter, curious why.
|
# ? Jun 16, 2011 04:07 |
|
Captain Capacitor posted:Edit: Way to edit your post and confuse people. Captain Capacitor posted:I'm using Carbon and Whisper as a backend/replacement for RRD. I run into the same trap I always run into -- this thing will be nice as soon as I have more than design docs and ugly prototypes that don't do anything. I suck at the long tail.
|
# ? Jun 16, 2011 04:11 |
|
bitprophet posted:
As much as I love ExtJS, I'm not a big fan of how Graphite is coupled with everything. I love the Dashboard and the pseudo command line, but I find it just mashed together with Django. I want the nice parsing, but want to couple it with Django my own way. Plus PyCairo is a pain in the rear end to install. I've actually submitted a proposal to rewrite the API using REST or SimpleAPI. Misogynist posted:
That's pretty awesome. We needed something with some real flexibility. Our software (running on EC2 to scale) pushes stats to AMQP, which Carbon pulls from. We needed to be able to just to toss new metrics at our monitor as instances go up and down. So I'm writing a frontend for it all, tearing the guts out of Graphite and using Highcharts.
|
# ? Jun 16, 2011 04:40 |
|
I'm having a pretty loving wierd problem thats got me mystified. Heres some registration code;- code:
code:
I'm loving mystified by this.
|
# ? Jun 16, 2011 12:39 |
|
Ended up solving this. Turns out the auth_users table was completely busted and not generating and emitting id field sequences. So when it would queue up a table write in the create_user, pgsql was returning a null for the id number. Consequently when you go to save() it, django goes "Ok, this hasn't been written to the db yet" and attempts an insert and the whole thing explodes in a ball of flames, rolling back the previous insert and crashing the app. That was a oval office to debug. Still not a fan of postgres folks.
|
# ? Jun 17, 2011 06:50 |
|
Back again! Hopefully this'll be my last time, as email handling is the last feature of this system I have to implement... anyway, my problem. I have this code for sending an email to a work order's author and all assignees: code:
What the gently caress? EDIT: I had it email me the assignees list and each email address is only listed once. DICTATOR OF FUNK fucked around with this message at 19:41 on Jun 21, 2011 |
# ? Jun 21, 2011 19:37 |
|
root beer posted:This works great, except for the part where the author and all assignees receive the email twice... but if the author is also assigned to the order, it still sends 2 emails, instead of 4 as I'd expect. (edit: also; the use of .distinct() may not do what you expect it to do, as its not directly analogous to most people's experience with DISTINCT in SQL. YMMV.) Yay fucked around with this message at 20:26 on Jun 21, 2011 |
# ? Jun 21, 2011 20:24 |
|
Yay posted:Likely this is because you've not set the dispatch_uid on the signal connector. See the outdated (but still largely correct) wiki on the subject, and the actual docs If I could find a way to donate to the Django thread I would
|
# ? Jun 21, 2011 20:39 |
|
Just a quick reminder to everyone that DjangoCon US is coming up soon (Sept 6-8) and early bird pricing ends on July 1. Also, if you want to submit a paper for a talk, that deadline is July 5. All the details are on http://djangocon.us.
|
# ? Jun 23, 2011 07:21 |
|
I can't believe I can't find a simple app/widget that adds jquery autocomplete searching to django. I have a model with 2 M2Ms fields, and I want to have a non-admin page with a search box to search a field in the model, or a field in the 2 M2Ms and let me go to a new page with the details. Every AJAX search type thing I've looked into is either admin only, based on a 5 year old jquery where the syntax has changed, or just didn't work when I tried it. I know it's popular to bash web2py, but at least there that poo poo was literally a one liner.
|
# ? Jun 24, 2011 18:27 |
|
|
# ? Jun 5, 2024 08:46 |
|
I've never used it but have you looked at https://github.com/jeffkistler/django-fancy-autocomplete ?
|
# ? Jun 24, 2011 23:39 |