Re: How do you pass dissimilar data from view to template?
Thanks for the additional thought on this. It is a much appreciated confirmation to me. Last night I was torturing my brain over the logistics of what I had conceived, and by this morning I had pretty much concluded that I would have to go the route you are suggesting. Now I just have to find an existing solution ... or learn Javascript. --Bill On Jan 27, 11:19 am, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote: > On Thu, 26 Jan 2012 14:01:50 -0800 (PST), BillB1951 <wjbur...@gmail.com> > wrote: > > >Brett, Thanks. That is what I needed. BillB1951 > > Just an aside: seems like a convoluted plan to keep round-tripping > to the server/database each time you refine the filter. > > I'm presuming the initial data set being sent is the "full" list. If > so, might it not be useful to somehow (Caveat: I'm /not/ skilled at > this, only toyed with Javascript too many years ago) embed a Javascript > action to count the categories, render the filter selections and, when > one is picked, have the Javascript modify the page in-place to display > only the filtered data? > > Granted, adding another language on top of Python, Django, and the > template language, may be more than desirable. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfr...@ix.netcom.com HTTP://wlfraed.home.netcom.com/ -- 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: How do you pass dissimilar data from view to template?
Brett, Thanks. That is what I needed. BillB1951 On Jan 26, 4:55 pm, Brett Epps <brett.e...@quest.com> wrote: > It sounds like you're confused about how to add more than one piece of > information to a template. When you render a template, the template is > given a context, which is a Python dict object. A dict is a bunch of > key-value pairs. So, right now, you're probably doing something like: > > return render_to_response('path/to/template.html', {'items': items}) > > Where items is a list of item objects. You can simply add more key-value > pairs to the dict to add your counts: > > items_25_to_50_count = Item.objects.filter(price__gte=25, > price__lte=50).count() > return render_to_response('path/to/template.html', > {'items': items, 'items_25_to_50_count': items_25_to_50_count}) > > Hopefully this helps with your question. > > Brett > > On 1/26/12 3:12 PM, "BillB1951" <wjbur...@gmail.com> wrote: > > > > > > > > >I am a relatively new to Django, and have just run into a wall, but I > >am sure this will be a cake walk for you veterans out there. I have a > >list of items I am displaying in a table in a template. That is no > >problem I create an object (list of values) in my view send it to the > >template and render the table. However, I would like to also show on > >my template a bunch of count()¹s displayed as links, that when clicked > >will further filter the list of items displayed. For example, I may > >have items in the list that cost between $25 and $50, my link would > >show that there are say 20 items that match that criteria. When the > >link is selected in sends a request to the url.py that in turn > >executes a view that further filters the queryset then renders > >template again. > > >How do I get the count() info to the template? I do not think I can > >send two separate lists (objects) to the template (at least I have not > >been able to figure out how yet). I think I need to get the counts at > >the view and then somehow append them to my list object, but I¹m not > >sure how to do that and also, not quite sure how to parse those values > >in the template. I want the counts to show separate from the table > >generated from my list object, and I am somewhat concerned I¹m going > >to mess up my table that is working fine now. > > >I would appreciate any suggestions you have about how to tackle this, > >and I would really appreciate code examples because I am still > >somewhat Python/Django code challenged. > > >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. -- 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.
How do you pass dissimilar data from view to template?
I am a relatively new to Django, and have just run into a wall, but I am sure this will be a cake walk for you veterans out there. I have a list of items I am displaying in a table in a template. That is no problem I create an object (list of values) in my view send it to the template and render the table. However, I would like to also show on my template a bunch of count()’s displayed as links, that when clicked will further filter the list of items displayed. For example, I may have items in the list that cost between $25 and $50, my link would show that there are say 20 items that match that criteria. When the link is selected in sends a request to the url.py that in turn executes a view that further filters the queryset then renders template again. How do I get the count() info to the template? I do not think I can send two separate lists (objects) to the template (at least I have not been able to figure out how yet). I think I need to get the counts at the view and then somehow append them to my list object, but I’m not sure how to do that and also, not quite sure how to parse those values in the template. I want the counts to show separate from the table generated from my list object, and I am somewhat concerned I’m going to mess up my table that is working fine now. I would appreciate any suggestions you have about how to tackle this, and I would really appreciate code examples because I am still somewhat Python/Django code challenged. 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: Model for images with thumbnails
You may want to check out a tutorial on lightbird.net link is: http://www.lightbird.net/dbe/photo.html Bill On Jan 6, 6:35 am, MeMEwrote: > Hello, > > I'm new to Django. I started to write something for personal > purposes. > I have doubts about writing model for media files, especially images. > In my app thumbnails should be automatically created when image is > uploaded. Each such image can have thumnails with different > dimensions. Images can be attached to posts. > > The question is how to store such information in database? > > Should it be separate records for each thumbnail and main image? And > how to keep relationship? > > Or maybe I could store everything in one record as a serialized data > (as in Wordpress)? Then I could as well store there HTML for image and > metadata. > > -- > Regards > MM -- 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.
Having trouble passing a parent table record “id” to a new record in a child table
I am having trouble passing a parent table record “id” to a new record in a child table. My urlconf calls add_childtable in my views.py and passes the parenttable_id to it. I have excluded the parenttable from my ChildTableForm(ModelForm) because I do not want it to be available to the users. When I hit submit – from my form.html I get a “KeyError” error message. The parenttable field/column (a ForeighKey field) does not want to accept the parenttable_id I am passing to it. What am I doing wrong? Example code snippets are always appreciated. Thanks, Bill PS. I notice that the code pasted in below seems to have messed up some of the indenting, but its correct in my python files. # models.py class ChildTable(models.Model): field1 = models.IntegerField(null=True, blank=True) field2 = models.CharField(max_length=35, blank=True) field3 = models.CharField(max_length=35, blank=True) parenttable = models.ForeignKey(ParentTable) class ChildTableForm(ModelForm): class Meta: model = ChildTable exclude = ('parenttable',) # views.py def add_childtable(request, parenttable_id): if request.method == 'POST': form = ChildTableForm(request.POST) if form.is_valid(): # create a new listing childtable = ChildTable.objects.create( field1=form.cleaned_data['field1'],built'], field2=form.cleaned_data['field2'],built'], field3=form.cleaned_data['field3'],built'], parenttable=form.cleaned_data[parenttable_id], ) # Always redirect after a POST return http.HttpResponseRedirect('/appdir/childtable/%s/' % childtable.id) else: # This the the first page load, display a blank form form = ChildTableForm() context = Context({'title': 'Add ChildTableData', 'form': form}) context.update(csrf(request)) return render_to_response('appdir/form.html', context) # form.html http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;> http://www.w3.org/1999/xhtml;> {{ title }} {{ title }} {% csrf_token %} {{ form.as_p }} -- 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.
error attempting to populate field
I am trying to add the interger value 15 to a table field CanoeKayak.listings, which is a Foreignkey field that is related to the "Listings.id" field in another table --- a listings.id=15 exists. What is happening? see error below: ValueError at /bsmain/canoekayak/add/15/ Cannot assign "[15]":"CanoeKayak.listings" must be a "Listings" instance. Request Method: POST Request URL:http://127.0.0.1:8000/bsmain/canoekayak/add/15/ Django Version: 1.3.1 Exception Type: ValueError Exception Value: Cannot assign "[15]": "CanoeKayak.listings" must be a "Listings" instance. Exception Location: /usr/local/lib/python2.6/dist-packages/django/db/ models/fields/related.py in __set__, line 331 Python Executable: /usr/bin/python Python Version: 2.6.5 Python Path: ['/home/bill/workspace/boatsite', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.6/gtk-2.0', '/usr/local/lib/python2.6/dist-packages'] Server time:Tue, 3 Jan 2012 21:33:38 -0600 -- 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: syncdb not finding and syncing my MySQL database
To clarify the I entered the command "python manage.py syncdb" from the the terminal prompt (current directory) which is consistent with my apps directory. Manage.py is in the project root and executes because its in my search path. I am currently at my day job so I am not able to send the trace-back. I'll do that tonight. I apologize for not providing better info. Bill On Nov 21, 1:29 pm, Furbee <furbeena...@gmail.com> wrote: > Yes, please offer more details. One thing I noticed off the bat, though, > was that you said you are running "python manage.py syncdb" from the > directory where your models.py is. The manage.py file is at the root of > your project, not in the apps folder(s) where models.py is. > > Furbee > > On Mon, Nov 21, 2011 at 10:13 AM, Anoop Thomas Mathew <atm...@gmail.com>wrote: > > > > > > > > > Hi, > > > "I am getting an error" > > This is not a proper way to ask question. Please post > > your trace-back somewhere and send the link to the group or at least > > specify what error is it, so that, we could help you. > > Thanks, > > Anoop > > > atm > > ___ > > Life is short, Live it hard. > > > On 21 November 2011 23:31, BillB1951 <wjbur...@gmail.com> wrote: > > >> Problem when I try to run "python manage.py" I get an error. It > >> appears that my MySQL database cannot be found, but syncdb know it's > >> name, which I assume it got from my settings.py file. > > >> Any suggests will be very much appreciated. Thanks > > >> Bill > > > -- > > 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. -- 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.
syncdb not finding and syncing my MySQL database
I am attempting to run "python manage.py syncdb" from my apps directory (directory where model.py exists for the app). The settings.py database settings all appear to be ok. I have created MySQL database with the same name as in settings.py and I have verified its creation on the MySQL server. I can make a connection to the MySQL server from from my apps directory. Problem when I try to run "python manage.py" I get an error. It appears that my MySQL database cannot be found, but syncdb know it's name, which I assume it got from my settings.py file. Any suggests will be very much appreciated. Thanks Bill -- 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.
Can't locate Django source code path
FRom part 2 of the tutorial I am instructed to copy a file --- Now copy the template admin/base_site.html from within the default Django admin template directory in the source code of Django itself (django/contrib/admin/templates) i I can't find the path. How do I get to it? -- 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 - tutorial part 2 problem - Permission denied when attempting to save file
Got this error Ran into this as part of the Django tutorial (part 2) very close to the bottom an attempt to change the page header/title. "There was an error attempting to save 'base_site.html':Permission denied" when trying to save the file below (copied from django source code) {% extends "admin/base.html" %} {% load i18n %} {% block title %}{{ title }} | {% trans 'Django site admin' %}{% endblock %} {% block branding %} {% trans 'Django administration' %} {% endblock %} {% block nav-global %}{% endblock %} any thoughts? -- 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.