Get results from query depending on another query
I have a model that has a FK to django.contrib.auth.models Group. I run a query that gets all the groups that a user is a member of: groups = Group.objects.filter(user=request.user) Then I want to run a query for that model that gets and entries in that model where the group FK is one of the groups in the groups query. So like: course = Course.objects.filter(group=groups) How can I do this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Help with schema
I have a site/database that tracks baseball players and their agents. Players can have multiple agents at one time, they also can fire agents and hire new ones at anytime, and I'd like to track all of their agents, current, or previous. I was thinking of this schema for my models, but wasn't sure the best way to handle the previous agents, etc. Also, players can rehire a previous agent... Would it be best to have another model that has a FK to player and MTM to agent with the dates of hire, fired? http://dpaste.com/41109/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
IndexError: list index out of range
I am trying to write to CSV, I was able to do so before, not sure what the problem is... When my query returns results, I get this error http://dpaste.com/96399/ Here's my view http://dpaste.com/96398/ If the query is empty it opens the CSV with only the header row... What am I doing wrong? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Switching from MySQL to PostgreSQL
We've been running our Django app with mod_python and Apache to serve static files, along with MySQL as the database of choice. We're in the process of making a few changes because we've had some stability and performance issues, so we're moving to mod_wsgi/nginx, but we also want to switch from MySQL to PostgreSQL. Is there an easy way for us to take all of our data from our MySQL and move it over to PostgreSQL? Chris --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django and Authorize.net
Greetings, We have an application for our school online, just recently the university controller and business office finally gave us clearance to accept our application fee online, and they setup an account with authorize.net. I'm trying to integrate the payment within our Application app, I was curious if anyone had done any one-off payments with Django/ authorize.net, or if there were and pluggable apps out there (I know Satchmo, that's my backup plan). Thanks, Chris -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Help Converting a Query getting one result using .filter() to .get()
I have this query, trying to get the next game in the future. today = datetime.datetime.now() next_game = Game.objects.filter(date__gt=today).order_by('date')[:1] I need to use .get() if possible, instead of .filter() how can I do this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Help Converting a Query getting one result using .filter() to .get()
Sorry, I should've said what I'm using it for... Here's my models http://dpaste.com/217686/ The query above I just want to get the next/upcoming game in the database, which I display on the sidebar of the front page. What I am trying to do, is also get ALL other entries from the database, in a separate query where sport=sport and opponent=opponent to figure out the historical Win/Loss record between the teams? On Jul 12, 8:15 pm, John M wrote: > Why does it matter? > > You could just say next_game[0] instead. > > J > > On Jul 12, 4:28 pm, Chris McComas wrote: > > > > > I have this query, trying to get the next game in the future. > > > today = datetime.datetime.now() > > next_game = Game.objects.filter(date__gt=today).order_by('date')[:1] > > > I need to use .get() if possible, instead of .filter() how can I do > > this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Comparing DateTimeField to datetime.now()
This is my model, I'm trying to set it so that if the game is in the future, based on the field date, then to return True, if not return False. http://dpaste.com/218111/ I am importing datetime in my models.py but for some reason it's giving me nothing. I tried displaying future and nothing shows up? What have I done wrong? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Comparing DateTimeField to datetime.now()
I'm using it in my template... Basically this http://dpaste.com/218114/ Mainly I want to use it for the {% if %} but I tried to just show it was well and still nothing... On Jul 14, 11:49 am, Daniel Roseman wrote: > On Jul 14, 4:43 pm, Chris McComas wrote: > > > This is my model, I'm trying to set it so that if the game is in the > > future, based on the field date, then to return True, if not return > > False. > > >http://dpaste.com/218111/ > > > I am importing datetime in my models.py but for some reason it's > > giving me nothing. I tried displaying future and nothing shows up? > > What have I done wrong? > > How/where are you calling this method? > -- > DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Comparing DateTimeField to datetime.now()
This worked: import datetime Then, use 'datetime.datetime.now()' instead of 'datetime.now()' Thanks guys! On Jul 14, 11:57 am, Subhranath Chunder wrote: > How did u import the datetime module? > If you did: > > a> > import datetime > Then, use 'datetime.datetime.now()' instead of 'datetime.now()' > > b> > from datetime import datetime > Then 'datetime.now()' should work correctly. > > Thanks, > Subhranath Chunder. > > On Wed, Jul 14, 2010 at 9:13 PM, Chris McComas wrote: > > > > > This is my model, I'm trying to set it so that if the game is in the > > future, based on the field date, then to return True, if not return > > False. > > >http://dpaste.com/218111/ > > > I am importing datetime in my models.py but for some reason it's > > giving me nothing. I tried displaying future and nothing shows up? > > What have I done wrong? > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com > groups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Help Reading data from an uploaded CSV
I have this code: http://dpaste.com/250981/ The file is uploading properly, but it is not creating any entries in my Pharmcas table, it's worked before, last spring when we used it last, but right now it's not working? It uploads and saves the file as it should, but then doesn't do any of the creating of entries in the table? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Help with Django and Apache
I have a site built with Django, we're switching things up and will be running ExpressionEngine as our main CMS for the "front-end" / marketing piece of our site. We will have two Django apps running elsewhere on the site, one is a Course Management Software we built in house, the other is an online application for our school. Right now our httpd.conf for Apache is: http://dpaste.com/141399/ What would be the best way to handle our new setup? Set to None then set and to the Python? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Division with Python/Django
I have this view with my form: http://dpaste.com/152046/ when I try to submit the form I'm getting this error: unsupported operand type(s) for //: 'unicode' and 'int' what did I do wrong? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Division with Python/Django
Changed my view to this: http://dpaste.com/152061/ This is the full error message: http://dpaste.com/152060/ The first three numbers, math_rawscore, science_rawscore, and socsci_rawscore are GPAs, like 4.0, 3.47, etc. The second two numbers pcat_rawscore and pcatessay_rawscore are whole numbers like 40 or 4 On Jan 29, 8:43 am, rebus_ wrote: > On 29 January 2010 14:40, Chris McComas wrote:> I > have this view with my form:http://dpaste.com/152046/when I try to > > submit the form I'm getting this error: unsupported operand type(s) > > for //: 'unicode' and 'int' what did I do wrong? > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > Are you sure cogability.* attributes are integers? > > Full error message would also be helpfull. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Division with Python/Django
The form is a ModelForm, where the fields involved, all of them are DecimalField() On Jan 29, 9:03 am, Chris McComas wrote: > Changed my view to this: > > http://dpaste.com/152061/ > > This is the full error message: > > http://dpaste.com/152060/ > > The first three numbers, math_rawscore, science_rawscore, and > socsci_rawscore are GPAs, like 4.0, 3.47, etc. The second two numbers > pcat_rawscore and pcatessay_rawscore are whole numbers like 40 or 4 > > On Jan 29, 8:43 am, rebus_ wrote: > > > > > On 29 January 2010 14:40, Chris McComas wrote:> I > > have this view with my form:http://dpaste.com/152046/whenI try to > > > submit the form I'm getting this error: unsupported operand type(s) > > > for //: 'unicode' and 'int' what did I do wrong? > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Django users" group. > > > To post to this group, send email to django-us...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > django-users+unsubscr...@googlegroups.com. > > > For more options, visit this group > > > athttp://groups.google.com/group/django-users?hl=en. > > > Are you sure cogability.* attributes are integers? > > > Full error message would also be helpfull. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Division with Python/Django
Hey everyone, here's all of the information: Here's the models: http://dpaste.com/152277/ Here's my view: http://dpaste.com/152061/ Here's the full error message: http://dpaste.com/152060/ On Jan 29, 9:13 am, Chris McComas wrote: > The form is a ModelForm, where the fields involved, all of them are > DecimalField() > > On Jan 29, 9:03 am, Chris McComas wrote: > > > > > Changed my view to this: > > >http://dpaste.com/152061/ > > > This is the full error message: > > >http://dpaste.com/152060/ > > > The first three numbers, math_rawscore, science_rawscore, and > > socsci_rawscore are GPAs, like 4.0, 3.47, etc. The second two numbers > > pcat_rawscore and pcatessay_rawscore are whole numbers like 40 or 4 > > > On Jan 29, 8:43 am, rebus_ wrote: > > > > On 29 January 2010 14:40, Chris McComas wrote:> > > > I have this view with my form:http://dpaste.com/152046/whenItry to > > > > submit the form I'm getting this error: unsupported operand type(s) > > > > for //: 'unicode' and 'int' what did I do wrong? > > > > > -- > > > > You received this message because you are subscribed to the Google > > > > Groups "Django users" group. > > > > To post to this group, send email to django-us...@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > django-users+unsubscr...@googlegroups.com. > > > > For more options, visit this group > > > > athttp://groups.google.com/group/django-users?hl=en. > > > > Are you sure cogability.* attributes are integers? > > > > Full error message would also be helpfull. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
help with Django model and 'choices'
I have this model http://dpaste.com/153722/ and I have a ModelForm for it on my site. When I complete the form it saves everything as it should and displays just a detail page for each entry with all of the correct information from the Model. When I go back to edit the form, or I view it in the CRUD admin that comes with Django the fields ha_grade and hp_grade do not display the previously selected grade, just the --- This is a big problem since we are constantly updating/editing these files for students and we don't want to have to reenter every grade, every time... What have I done wrong? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: help with Django model and 'choices'
Here's my model form: http://dpaste.com/153728/ The info isn't being saved as an empty value. When I view my db with phpmyadmin, the correct values are in the ha_grade and hp_grade field in the db, the drop-down list on the forms is just not displaying them as being 'selected'. On Feb 2, 10:09 am, Shawn Milochik wrote: > If you post the ModelForm we might be able to help more, but I'll venture a > guess. > > Do you have any templates where you use this ModelForm but do not show the > grades for editing? If so, and someone does an update, you're saving those > fields with empty values unless you explicitly exclude them in the ModelForm > meta information. > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: help with Django model and 'choices'
Here's my view: http://dpaste.com/153735/ One thing I just thought of, is it a problem that the data for ha_grade and hp_grade are saved in the db as 4.3300 or 4. or 3.6700 but in the on my form they're like this: 4.33 or 4.0 or 3.67 ??? On Feb 2, 10:32 am, Shawn Milochik wrote: > Okay. Sorry, I don't see anything in the model or ModelForm that seem like > they might cause this behavior. How about the view(s) that instantiate the > ModelForm? > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: help with Django model and 'choices'
Here's the view... http://dpaste.com/153735/ Could it possibly be that the grade is saved in the db as 4.3300 or 4. or 3.6700 but when I view source the select on the form looks like this: - A+ A A- B+ B B- C+ C C- CR On Feb 2, 10:32 am, Shawn Milochik wrote: > Okay. Sorry, I don't see anything in the model or ModelForm that seem like > they might cause this behavior. How about the view(s) that instantiate the > ModelForm? > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: help with Django model and 'choices'
Thnx. The reason the grade values are 4.33, 4. 3.67 etc is because that value is multiplied by the value entered for ha_credithours and hp_credithours. If there's a better way to do this from the beginning, like changing the values for the grade_choices and then multiplying it different in my views that'd be fine as well... On Feb 2, 10:56 am, Shawn Milochik wrote: > On Feb 2, 2010, at 10:40 AM, Chris McComas wrote: > > > Here's my view: > > >http://dpaste.com/153735/ > > > One thing I just thought of, is it a problem that the data for > > ha_grade and hp_grade are saved in the db as 4.3300 or 4. or > > 3.6700 but in the on my form they're like this: 4.33 or 4.0 > > or 3.67 ??? > > Your guess sounds likely. I wanted to see the view to see if anything was > going on with the grades, but it doesn't appear so. > > Here's a hacky fix that should work (untested). Hopefully someone can offer > the proper solution once they see this ugliness: > > Add this to your ModelForm: > > def __init__(self, *args, **kwargs): > > super(GreenSheetsForm, self).__init__(self, *args, **kwargs) > > if self.instance: > for choice_id, choice_text in self.fields['hp_grade'].choices: > if Decimal(choice_id) == self.instance.hp_grade: > self.fields['hp_grade'].initial = choice_id > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: help with Django model and 'choices'
Shawn -> thnx for your help, that "hacky" fix isn't working tho... On Feb 2, 11:09 am, Chris McComas wrote: > Thnx. The reason the grade values are 4.33, 4. 3.67 etc is because > that value is multiplied by the value entered for ha_credithours and > hp_credithours. If there's a better way to do this from the beginning, > like changing the values for the grade_choices and then multiplying it > different in my views that'd be fine as well... > > On Feb 2, 10:56 am, Shawn Milochik wrote: > > > > > On Feb 2, 2010, at 10:40 AM, Chris McComas wrote: > > > > Here's my view: > > > >http://dpaste.com/153735/ > > > > One thing I just thought of, is it a problem that the data for > > > ha_grade and hp_grade are saved in the db as 4.3300 or 4. or > > > 3.6700 but in the on my form they're like this: 4.33 or 4.0 > > > or 3.67 ??? > > > Your guess sounds likely. I wanted to see the view to see if anything was > > going on with the grades, but it doesn't appear so. > > > Here's a hacky fix that should work (untested). Hopefully someone can offer > > the proper solution once they see this ugliness: > > > Add this to your ModelForm: > > > def __init__(self, *args, **kwargs): > > > super(GreenSheetsForm, self).__init__(self, *args, **kwargs) > > > if self.instance: > > for choice_id, choice_text in > > self.fields['hp_grade'].choices: > > if Decimal(choice_id) == self.instance.hp_grade: > > self.fields['hp_grade'].initial = choice_id > > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: help with Django model and 'choices'
Like this? http://dpaste.com/153790/ On Feb 2, 12:19 pm, Shawn Milochik wrote: > On Feb 2, 2010, at 11:49 AM, Chris McComas wrote: > > > Shawn -> thnx for your help, that "hacky" fix isn't working tho... > > Sorry 'bout that. I didn't really test it. But in the loop, do some creative > print or log.debug statements with the values in scope and see what you can > figure out. Maybe you can fix the hack. > > However, as you suggested maybe you can change the models, create a property > function that returns the desired value, then create a South migration. > > Also, I'm just realized something I completely overlooked. Know your GRADES > tuple? The first value in each element is a float, not a Decimal. Try > importing decimal.Decimal and replacing the values of your grades (APLUS, > BMINUS, etc.) with Decimal(APLUS), Decimal(BMINUS), etc. See if that fixes it. > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: help with Django model and 'choices'
Nope. I dropped the table completely and started from scratch. I'm still testing it out, so there hasn't been any real data entered so I can play around with it. I dropped the table, uploaded my new models, syncdb, and then filled out a form, saved it. It saved properly, went back to edit the form and it's still not showing anything as for ha_grade or hp_grade. The drop-down for each still lists the value as 4.33 or 4.0 or 3.67 etc? On Feb 2, 12:51 pm, Shawn Milochik wrote: > On Feb 2, 2010, at 12:48 PM, Chris McComas wrote: > > > Like this? > > >http://dpaste.com/153790/ > > Yeah. Does that help with the pre-population in your form? > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: help with Django model and 'choices'
I dropped the table again, and changed the fields in my model from DecimalField to FloatField. Now it works, it'll display the proper option that's been selected. However, when I try to save it on the form I created in my view, it'm getting this error: http://dpaste.com/153802/ Ugh. Ha On Feb 2, 1:03 pm, Chris McComas wrote: > Nope. I dropped the table completely and started from scratch. I'm > still testing it out, so there hasn't been any real data entered so I > can play around with it. I dropped the table, uploaded my new models, > syncdb, and then filled out a form, saved it. It saved properly, went > back to edit the form and it's still not showing anything as > for ha_grade or hp_grade. The drop-down for each > still lists the value as 4.33 or 4.0 or 3.67 etc? > > On Feb 2, 12:51 pm, Shawn Milochik wrote: > > > > > On Feb 2, 2010, at 12:48 PM, Chris McComas wrote: > > > > Like this? > > > >http://dpaste.com/153790/ > > > Yeah. Does that help with the pre-population in your form? > > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: help with Django model and 'choices'
Again, this is my view: http://dpaste.com/153735/ I'm thinking the error is in someway related to this line: new_green.hp_coursepoints = new_green.hp_grade * hp_credithours The only thing I changed was changed hp_grade from a DecimalField to FloatField On Feb 2, 1:14 pm, Chris McComas wrote: > I dropped the table again, and changed the fields in my model from > DecimalField to FloatField. Now it works, it'll display the proper > option that's been selected. However, when I try to save it on the > form I created in my view, it'm getting this error: > > http://dpaste.com/153802/ > > Ugh. Ha > > On Feb 2, 1:03 pm, Chris McComas wrote: > > > > > Nope. I dropped the table completely and started from scratch. I'm > > still testing it out, so there hasn't been any real data entered so I > > can play around with it. I dropped the table, uploaded my new models, > > syncdb, and then filled out a form, saved it. It saved properly, went > > back to edit the form and it's still not showing anything as > > for ha_grade or hp_grade. The drop-down for each > > still lists the value as 4.33 or 4.0 or 3.67 etc? > > > On Feb 2, 12:51 pm, Shawn Milochik wrote: > > > > On Feb 2, 2010, at 12:48 PM, Chris McComas wrote: > > > > > Like this? > > > > >http://dpaste.com/153790/ > > > > Yeah. Does that help with the pre-population in your form? > > > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: help with Django model and 'choices'
Gleber, I'll try that as well. If I can just figure out how to multiply total = = new_green.hp_grade * hp_credithours Where hp_grade is a FloatField (double in the MySQL db) with hp_credithours which is a DecimalField (decimal in the MySQL db) I think they'd solve the problem. On Feb 2, 2:25 pm, Gleber wrote: > Try surround the values of the constants with Decimal("x"), like: > > APLUS = Decimal("4.33") > A = Decimal("4") > AMINUS = Decimal("3.67") > ... > > On Feb 2, 4:58 pm, raj wrote: > > > > > To populate a ModelMultipleChoiceField of a ModelForm I'd used a hack > > similar to Shawn's initial suggestion. So I hope this will work: > > > Add to your modelform: > > > def __init__(self, whatever_there_are_as_args): > > super() # with usual syntax and required_args > > if instance is not None and self.initial is not None: > > self.initial.update({'hp_grade':instance.hp_grade}) > > elif instance is not None: > > self.initial = {'hp_grade':instance.hp_grade} > > > I haven't tested this specific lines but the original code works for > > me. > > > Rajeesh. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: help with Django model and 'choices'
This is my view: http://dpaste.com/154088/ I did some testing and the error is coming from this line: new_green.hp_coursepoints = new_green.hp_grade * hp_credithours Here's my model now: http://dpaste.com/154091/ Any ideas on how to fix this and the math work? hp_coursepoints is a DecimalField hp_grade is a FloatField hp_credithours is a DecimalField I tried this, but no luck: new_green.hp_coursepoints = Decimal(new_green.hp_grade) * hp_credithours On Feb 2, 2:27 pm, Chris McComas wrote: > Gleber, > > I'll try that as well. If I can just figure out how to multiply > > total = = new_green.hp_grade * hp_credithours > > Where hp_grade is a FloatField (double in the MySQL db) with > hp_credithours which is a DecimalField (decimal in the MySQL db) I > think they'd solve the problem. > > On Feb 2, 2:25 pm, Gleber wrote: > > > > > Try surround the values of the constants with Decimal("x"), like: > > > APLUS = Decimal("4.33") > > A = Decimal("4") > > AMINUS = Decimal("3.67") > > ... > > > On Feb 2, 4:58 pm, raj wrote: > > > > To populate a ModelMultipleChoiceField of a ModelForm I'd used a hack > > > similar to Shawn's initial suggestion. So I hope this will work: > > > > Add to your modelform: > > > > def __init__(self, whatever_there_are_as_args): > > > super() # with usual syntax and required_args > > > if instance is not None and self.initial is not None: > > > self.initial.update({'hp_grade':instance.hp_grade}) > > > elif instance is not None: > > > self.initial = {'hp_grade':instance.hp_grade} > > > > I haven't tested this specific lines but the original code works for > > > me. > > > > Rajeesh. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: help with Django model and 'choices'
Javier, WORKED PERFECT! THANK YOU ALL SO MUCH! :) On Feb 3, 9:50 am, Javier Rivera wrote: > Chris McComas wrote: > > I tried this, but no luck: > > > new_green.hp_coursepoints = Decimal(new_green.hp_grade) * > > hp_credithours > > Decimal can't directly convert floats to decimals. > > Try: > > new_green.hp_coursepoints = Decimal(str(new_green.hp_grade)) * > hp_credithours > > or > > new_green.hp_coursepoints = Decimal("%.2f" % new_green.hp_grade) * > hp_credithours > > if you prefer to round hp_grade to a fixed number of decimals before > doing the math. > > Javier. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Help with math functions...
This is kinda of a general and kind of a specific question. I have this in my view: http://dpaste.com/154208/ The first line adds up perfectly, but the second one doesn't and throws an index out of range error. What is the problem? cog.interview_score and cog.interview_score_conv are both DecimalFields. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
If query field equals text...
I'm trying to run this IF in my views, it's throwing an index out of range error. http://dpaste.com/154249/ What have I done wrong? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: If query field equals text...
Sorry, I've tried a few things... What kind of sucks is I'm just getting an IndexError: list index out of range which isn't very descriptive. I know the 'lor' query works, I tweaked my view to this: http://dpaste.com/154251/ I just put a HttpResponseRedirect below the 'if lor:' to make sure that was working and it is working, so the problem as I can tell is with the line(s) if lor.rating_recommendation == "I highly recommend this applicant without any reservations." I tried to change it to http://dpaste.com/154252/ but that's not right and threw a bad syntax error. The field rating_recommendation is a CharField in my model/db. On Feb 3, 2:58 pm, Shawn Milochik wrote: > On Feb 3, 2010, at 2:52 PM, Chris McComas wrote: > > > I'm trying to run this IF in my views, it's throwing an index out of > > range error. > > >http://dpaste.com/154249/ > > > What have I done wrong? > > Not reading this, mostly:http://catb.org/~esr/faqs/smart-questions.html > > To be slightly more specific, what exactly have you tried to find the cause > of this problem? Notice I say 'cause,' and not 'solution.' > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Feedback on Models setup
I have a Course Management System I've developed here at work. Faculty can login and upload lectures, course resources, etc to classes they teach, along with general course information. Students can login to view their courses, download lectures, resources, get announcements from their faculty members, etc. My model as is: http://dpaste.com/156737/ What I'm trying to figure out is the best method to assign students to courses. We'd like the ability to have all students in one group, there are a couple courses that are for all students regardless of freshman, sophomore, etc. Also, we'd like to have groups for each class year, Freshman, Sophomore, Junior, Senior, also, we'd like the option to individually add students to certain courses, so a freshman could be added to a junior class. Also, we want the option to exclude individuals from a course, so if all but 5 of the 80 freshman are in a class, we can add the group to the class, but just exclude those five (could do so with .exclude() in a query). So would it make sense to have this in my Courses model? - A ManyToManyField to groups that include All Students, Freshman, Sophomores, Juniors, Seniors that will add all students in each group to a course - A ManyToManyField with a list of all students to individually add these students to a course if they're Group is not already added - A ManyToManyField with a list of all students to individually EXCLUDE these students to a course if they're Group is added -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Index Error with empty queries
I have this in my views, if there lor1 and lor2 are both there it works fine, but if one or two of them are missing then it gives me this error. views.py - http://dpaste.com/161124/ error - http://dpaste.com/161128/ Some applicants have two LORs, some have one LOR, and obviously some don't have any. If it only has one, then cog.letter_rec_1 should have a value while cog.letter_rec_2 should be NULL. If they have no LORs then both cog.letter_rec_1 and cog.letter_rec_2 should be NULL. What have I done wrong in my views? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Help with Date Functions
These are my models: http://dpaste.com/166906/ I have a ModelForm setup, nothing special, just excluding a couple fields: application, tuition_deadline, and deadline_passed What I'm trying to do in my view is if a value is entered in read_receipt then it automatically sets tuition_deadline to be 7 days from that date. Here's my basic view: http://dpaste.com/166907/ How can I do that? I'm not really up to speed with the time/datetime functions in Python. Thanks, Chris -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Help with Date Functions
I tried this: new_admit.read_receipt.datetime.timedelta(days=7) and I got this error: http://dpaste.com/166919/ On Mar 2, 9:51 am, Masklinn wrote: > On 2 Mar 2010, at 15:45 , Chris McComas wrote: > > > > > These are my models:http://dpaste.com/166906/ > > > I have a ModelForm setup, nothing special, just excluding a couple > > fields: application, tuition_deadline, and deadline_passed > > > What I'm trying to do in my view is if a value is entered in > > read_receipt then it automatically sets tuition_deadline to be 7 days > > from that date. Here's my basic view:http://dpaste.com/166907/ > > > How can I do that? I'm not really up to speed with the time/datetime > > functions in Python. > > I think you could just add a datetime.timedelta(days=7)[1] to your > read_receipt, and set that as your tuition_deadline. > > [1]http://docs.python.org/library/datetime.html#timedelta-objects -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Help with Date Functions
Crap my bad, just under the gun to get this done and I overlook easy stuff. Sorry guys, thanks so much for your help! On Mar 2, 10:11 am, raj wrote: > Now that's a pure python typo. You must add(+) datetime.timedelta to > read_receipt. > > On Mar 2, 8:01 pm, Chris McComas wrote: > > > > > I tried this: > > > new_admit.read_receipt.datetime.timedelta(days=7) > > > and I got this error: > > >http://dpaste.com/166919/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Help with Date Functions
One more question...I'm trying in my view to say if the deadline has passed to make that field as True, if not False I have this view: http://dpaste.com/166951/ This is the error I get: http://dpaste.com/166952/ On Mar 2, 10:12 am, Chris McComas wrote: > Crap my bad, just under the gun to get this done and I overlook easy > stuff. Sorry guys, thanks so much for your help! > > On Mar 2, 10:11 am, raj wrote: > > > > > Now that's a pure python typo. You must add(+) datetime.timedelta to > > read_receipt. > > > On Mar 2, 8:01 pm, Chris McComas wrote: > > > > I tried this: > > > > new_admit.read_receipt.datetime.timedelta(days=7) > > > > and I got this error: > > > >http://dpaste.com/166919/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Uploading CSV file via ModelForm and then getting info and storing in a different model
I have to models, one is just a timestamp field and a file, the other has some information. I need to create a view that'll allow our staff to upload a CSV and then it'll automatically take that info and save it into the second model. I found this http://blog.2theleft.la/2010/02/9/importing-csv-files-django-python/ but my question is, in my view how would I call the file that was uploaded? View: http://dpaste.com/176327/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Uploading CSV file via ModelForm and then getting info and storing in a different model
derek, thanks, that's a bit much for what we need. i setup this in my views: http://dpaste.com/176380/ I'm getting this error: http://dpaste.com/176382/ How can I get it to open the file that was just uploaded and saved? On Mar 26, 9:27 am, derek wrote: > On Mar 26, 1:54 pm, Chris McComas wrote: > > > I have to models, one is just a timestamp field and a file, the other > > has some information. I need to create a view that'll allow our staff > > to upload a CSV and then it'll automatically take that info and save > > it into the second model. I found > > thishttp://blog.2theleft.la/2010/02/9/importing-csv-files-django-python/ > > but my question is, in my view how would I call the file that was > > uploaded? > > > View:http://dpaste.com/176327/ > > Chris > > Have a look at :http://code.google.com/p/django-batchimport/ > > HTH. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Uploading CSV file via ModelForm and then getting info and storing in a different model
So I resolved the previous issue, not i'm getting this error, newline in string. http://dpaste.com/176429/ Any idea? I'm thinking for some reason I need to change something in reader = csv.reader(file, delimiter=',', quotechar='"') On Mar 26, 10:27 am, Chris McComas wrote: > derek, > > thanks, that's a bit much for what we need. i setup this in my views: > > http://dpaste.com/176380/ > > I'm getting this error: > > http://dpaste.com/176382/ > > How can I get it to open the file that was just uploaded and saved? > > On Mar 26, 9:27 am, derek wrote: > > > > > On Mar 26, 1:54 pm, Chris McComas wrote: > > > > I have to models, one is just a timestamp field and a file, the other > > > has some information. I need to create a view that'll allow our staff > > > to upload a CSV and then it'll automatically take that info and save > > > it into the second model. I found > > > thishttp://blog.2theleft.la/2010/02/9/importing-csv-files-django-python/ > > > but my question is, in my view how would I call the file that was > > > uploaded? > > > > View:http://dpaste.com/176327/ > > > Chris > > > Have a look at :http://code.google.com/p/django-batchimport/ > > > HTH. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Running Shell script to run Django shell and then scp files to server...
I have a script in Django that I run manually 'python manage.py shell' and then 'from sports import scores' and it goes out and pulls scores from a couple URLs, modifies the data, and saves it to a SQLite database. Once that process runs I manually scp my files to a server... What I'd like to do is write a shell script that I can run on a cron to run the process at set periods, both actions. How would I do this so it properly runs the Django shell script? -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/yz98mwN3j_EJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Parsing feeds that are imported
This could be the wrong place to ask (maybe a BeautifulSoup) question... I have a Django app that is based around the Django Community Aggregator, it gets feeds from various sites and displays them on my site. What I am wanting to do, if possible, is when it gets a feed if a certain zip code is the feed Title or Summary then I want to create a entry for that zipcode with that feed? I have a model for the zip codes, so the list to compare should be pulled from that. There'd be a cron that'd run to do this, so for example if one of the zip codes is 12345 and one of the feeds it gets on the hourly cron has 12345 in the summary, then it'd go to the model linking the two and create/save an entry. Here are the pertinent models: http://dpaste.com/551223/ Thanks, -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Parsing feeds that are imported
Also, using the update_feeds that's part of the Django Community Aggregator worked initially, but I started over adding a m2m field on the Feed model for Sites. I'll have several "sites" as part of the Django app, like team1.mysite.com, team2.mysite.com, etc. When I added that field to the models and tried to run the update_feeds script it did nothing. It didn't import the feeds, didn't throw an error, etc. update_feeds: https://github.com/django/djangoproject.com/blob/master/django_website/aggregator/management/commands/update_feeds.py my models: http://dpaste.com/551322/ Thanks, On Jun 6, 4:55 pm, Chris McComas wrote: > This could be the wrong place to ask (maybe a BeautifulSoup) > question... > > I have a Django app that is based around the Django Community > Aggregator, it gets feeds from various sites and displays them on my > site. What I am wanting to do, if possible, is when it gets a feed if > a certain zip code is the feed Title or Summary then I want to create > a entry for that zipcode with that feed? > > I have a model for the zip codes, so the list to compare should be > pulled from that. There'd be a cron that'd run to do this, so for > example if one of the zip codes is 12345 and one of the feeds it gets > on the hourly cron has 12345 in the summary, then it'd go to the model > linking the two and create/save an entry. > > Here are the pertinent models:http://dpaste.com/551223/ > > Thanks, -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Parsing feeds that are imported
Chris, Thanks, the django community aggregator is built on top of the Universal Feed Parser. I figured out the zip codes function of my app. What I can't figure out is why when I add a m2m model to my update_feeds.py does not work. As far as I can tell in the update_feeds doesn't access the Feed model and save it anywhere. On Jun 7, 10:34 am, Chris Lawlor wrote: > I've not used the django community aggregator, so I'm making some > assumptions about it's functionality. If that app were to emit a > signal for each feed entry that it processed, it would be fairly > simple to write a signal handler that would create the associations > that you want. With this approach, you wouldn't need another cron job, > your processing would be done at the same time as django community > aggregator's. > > If you do need to do some manual feed parsing, you might try using the > Universal Feed Parser python module:http://feedparser.org/. It's > specifically designed for parsing RSS / Atom feeds, and so may be > somewhat more useful than BeautifulSoup. > > On Jun 6, 10:59 pm, Chris McComas wrote: > > > > > > > > > Also, using the update_feeds that's part of the Django Community > > Aggregator worked initially, but I started over adding a m2m field on > > the Feed model for Sites. I'll have several "sites" as part of the > > Django app, like team1.mysite.com, team2.mysite.com, etc. > > > When I added that field to the models and tried to run the > > update_feeds script it did nothing. It didn't import the feeds, didn't > > throw an error, etc. > > > update_feeds:https://github.com/django/djangoproject.com/blob/master/django_websit... > > my models:http://dpaste.com/551322/ > > > Thanks, > > > On Jun 6, 4:55 pm, Chris McComas wrote: > > > > This could be the wrong place to ask (maybe a BeautifulSoup) > > > question... > > > > I have a Django app that is based around the Django Community > > > Aggregator, it gets feeds from various sites and displays them on my > > > site. What I am wanting to do, if possible, is when it gets a feed if > > > a certain zip code is the feed Title or Summary then I want to create > > > a entry for that zipcode with that feed? > > > > I have a model for the zip codes, so the list to compare should be > > > pulled from that. There'd be a cron that'd run to do this, so for > > > example if one of the zip codes is 12345 and one of the feeds it gets > > > on the hourly cron has 12345 in the summary, then it'd go to the model > > > linking the two and create/save an entry. > > > > Here are the pertinent models:http://dpaste.com/551223/ > > > > Thanks, -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Help with custom model method for query
I have this views.py and models.py: http://dpaste.com/552615/ On the view what I want to do is display a list of all the feed types (News, Sports, etc general categories), then then below each of those feed type headings display the FeedItems for each feed for that city. Prior to adding the City model it was pretty easy, I was able to just do this in my template: http://dpaste.com/552616/ Maybe it's because it's late and I'm out of coffee, but this is totally stumping me on how to do this best. Any help would be greatly appreciated! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Help with custom model method for query
Thanks very much! The city is passed to the view as an argument. How would I run the regroup? I'm on the road and not around my laptop for a few hours. would it be: {% regroup feeds by type as feed_list %} {% for type by feed_list %} {{ type.name }} {% for entry in feed.list %} {{ entry.title }} {% endfor %} {% endfor %} On Jun 10, 6:21 am, bruno desthuilliers wrote: > On Jun 10, 6:13 am, Chris McComas wrote: > > > I have this views.py and models.py: > > >http://dpaste.com/552615/ > > > On the view what I want to do is display a list of all the feed types > > (News, Sports, etc general categories), then then below each of those > > feed type headings display the FeedItems for each feed for that city. > > Which city ? > > > Prior to adding the City model it was pretty easy, I was able to just > > do this in my template: > > >http://dpaste.com/552616/ > > > Maybe it's because it's late and I'm out of coffee, but this is > > totally stumping me on how to do this best. Any help would be greatly > > appreciated! > > Assuming the city is passed as an argument to the view (dummy code, > may have a few errors): > > # views.py > > def news(request, city_id): > city = get_object_or_404(City, pk=city_id) > feeds = Feed.objects.filter(city=city).select_related("type") > return render_to_response( > "path/to/template.html", > dict(city=city, feeds=feeds) > ) > > then in you template you just {% regroup %} feeds by > type,cfhttps://docs.djangoproject.com/en/1.3/ref/templates/builtins/#regroup -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Help with custom model method for query
tethered my phone to my laptop to test it out...have this code in my template: {% regroup feeds by feed_type as feed_list %} {% for feed_type in feed_list %} {{ feed_type.grouper }} {% for entry in feed_type.list %} {{ entry.title }} {% endfor %} {% endfor %} it does the first {% for %} loop perfectly, the second {% for %} loop gets the Feed from the database for that FeedType, but I need it to get FeedItems for Feed in FeedType Thanks for any help On Jun 10, 8:54 am, Chris McComas wrote: > Thanks very much! > > The city is passed to the view as an argument. > > How would I run the regroup? I'm on the road and not around my laptop > for a few hours. > > would it be: > > {% regroup feeds by type as feed_list %} > {% for type by feed_list %} > {{ type.name }} > > {% for entry in feed.list %} > {{ entry.title }} > {% endfor %} > > {% endfor %} > > On Jun 10, 6:21 am, bruno desthuilliers > > > > > > > > wrote: > > On Jun 10, 6:13 am, Chris McComas wrote: > > > > I have this views.py and models.py: > > > >http://dpaste.com/552615/ > > > > On the view what I want to do is display a list of all the feed types > > > (News, Sports, etc general categories), then then below each of those > > > feed type headings display the FeedItems for each feed for that city. > > > Which city ? > > > > Prior to adding the City model it was pretty easy, I was able to just > > > do this in my template: > > > >http://dpaste.com/552616/ > > > > Maybe it's because it's late and I'm out of coffee, but this is > > > totally stumping me on how to do this best. Any help would be greatly > > > appreciated! > > > Assuming the city is passed as an argument to the view (dummy code, > > may have a few errors): > > > # views.py > > > def news(request, city_id): > > city = get_object_or_404(City, pk=city_id) > > feeds = Feed.objects.filter(city=city).select_related("type") > > return render_to_response( > > "path/to/template.html", > > dict(city=city, feeds=feeds) > > ) > > > then in you template you just {% regroup %} feeds by > > type,cfhttps://docs.djangoproject.com/en/1.3/ref/templates/builtins/#regroup -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Help with custom model method for query
Sorry for the confusion, this is what I am trying to achieve. It's the FeedType and then FeedItems whose feed (fk) has a (fk) to FeedType. The HTML would be: {% for feed_type in FeedType %} {{ feed_type.name {% for FeedItem in Feed in FeedType %} {{ feeditem.title }} {% endfor %} Your code had me displaying each Feed of FeedType and then each FeedItem under it's appropriate Feed. What I'm trying to do is display each FeedType and directly under it the FeedItems. Make sense? Sorry this is confusing! On Jun 10, 10:02 am, bruno desthuilliers wrote: > On Jun 10, 3:12 pm, Chris McComas wrote: > > > tethered my phone to my laptop to test it out...have this code in my > > template: > > > {% regroup feeds by feed_type as feed_list %} > > {% for feed_type in feed_list %} > > {{ feed_type.grouper }} > > > {% for entry in feed_type.list %} > > {{ entry.title }} > > {% endfor %} > > {% endfor %} > > > it does the first {% for %} loop perfectly, the second {% for %} loop > > gets the Feed from the database for that FeedType, > > ??? Not sure I understand what you mean... > > > but I need it to > > get FeedItems for Feed in FeedType > > You mean something like this ? > > {% regroup feeds by feed_type as feed_list %} > > > {% for feed_type in feed_list %} > > {{ feed_type.grouper }} > > {% for feed in feed_type.list %} > > {{ feed.title }} > > {% for feeditem in feed.items %} > {{ item.title }} > {% endfor %} > > > {% endfor %} > > > {% endfor %} > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Help with custom model method for query
Bruno, Thanks. It wasn't exactly working properly, so I just had to add .order_by('feed__feed_type__order_by') and it seems to be working properly. On Jun 10, 3:33 pm, bruno desthuilliers wrote: > On 10 juin, 17:23, Chris McComas wrote: > > > Sorry for the confusion, this is what I am trying to achieve. It's the > > FeedType and then FeedItems whose feed (fk) has a (fk) to FeedType. > > > The HTML would be: > > > {% for feed_type in FeedType %} > > {{ feed_type.name > > > > {% for FeedItem in Feed in FeedType %} > > {{ feeditem.title }} > > > > {% endfor %} > > Ok. > > Then you need to correct your view: > > # views.py > > def news(request, city_id): > city = get_object_or_404(City, pk=city_id) > feeditems = > FeedItem.objects.filter(feed__city=city).select_related(depth=2) > return render_to_response( > "path/to/template.html", > dict(city=city, feeditems=feeditems) > ) > > And then in your template: > > {% regroup feeditems by feed_type as feeditems_list %} > > {% for feed_type in feeditems_list %} > > {{ feed_type.grouper }} > > {% for entry in feed_type.list %} > {{ entry.title }} > {% endfor %} > > > {% endfor %} > > > Obviously untested code, but this should work or, at least, get you > started. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Help with Multiple Databases Master/Slave
I have this database setup: http://dpaste.com/553289/ This is my db router file: http://dpaste.com/553290/ When I try to run ./manage.py syncdb --database=slave1 it starts to create the tables, but when it gets to the auth_permission table I get this error: django.db.utils.IntegrityError: duplicate key value violates unique constraint "auth_permission_content_type_id_codename_key" DETAIL: Key (content_type_id, codename)=(19, add_registrationprofile) already exists. I looked in my master db and there is only one entry for the one that's throwing the error. Any ideas what I can do? I have the django- registration app installed and that's where the permission is coming from. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Feed Parser, Community Aggregator, Date and Time settings
I'm using the Django community aggregator on my site, which uses the Universal Feed Parser to parse RSS feeds and save them in a database. I noticed that the date_modified for feeds were actually +5 of my timezone, which is set to America/Detroit in my Django settings. I'm on DotCloud and unfortunately I'm not able to set any Environment Variables (yet, they say they're working on that) and the default timezone on there is UTC. I don't mind that the field is saved in the database in the UTC timezone, that's probably best. What I need to do, and have fought for two days to do is convert it to Eastern Timezone when displayed on the site. Also, I use the timesince template tag on a couple pages that need to do a time since now to the feed item's date_modified both in Eastern Timezone. Any ideas? Suggestions? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Help with Templates and ljust
I have this as my template code: http://dpaste.com/555651/ This is the HTML it is outputting, which makes sense. What I'm trying to do is make it so the closing tag is right after the team name and the whitespace from the ljust after it. http://dpaste.com/555649/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Help with Templates and ljust
Figured it out. Added this to my Model: @property def spacer(self): return (25-len(str(self.team.name)))*' ' then in my template just added {{ team.spacer }} On Jun 17, 7:17 pm, Chris McComas wrote: > I have this as my template code: > > http://dpaste.com/555651/ > > This is the HTML it is outputting, which makes sense. What I'm trying > to do is make it so the closing tag is right after the team name > and the whitespace from the ljust after it. > > http://dpaste.com/555649/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Help selecting info from across databases in queries.
Here are my models: http://dpaste.com/558411/ I'm wanting to run a query on the Team model that gets every game from Games where the team's opponent was in the Coaches Poll Top 25. So, the view is getting: team = Team.objects.get(pk=team_id) On this page, it'll display team info (I cut out location, and more fields in the Team model that are just kind of fluff info), then I want to display below that every game from the Games table where the the team played an opponent who has an entry in TeamInfo.coaches that is less than, or equal to, 25. I can get all the teams games by: games = Games.objects.filter( Q(team1__team__team=team) | Q(team2__team__team=team)) I just don't know how to get the stuff from TeamInfo that I need. Should I restructure my models? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.