Re: Problem with generic views
Actually, As he didn't provide a template_object_name parameter, the generic view's default context variable is object_list. -justin On Fri, Jun 26, 2009 at 8:18 PM, maplyewrote: > > task_list not Task.object.all in the view. > > 2009/6/27 Technicalbard : >> >> Hey all, >> >> I did the tutorial, yet when I try to apply what I've learned (or >> think I've learned), to my own application it doesn't work... >> >> My code looks like this: >> >> # taskmgr/models.py >> class Task(models.Model): >> name = models.CharField(max_length=216) >> summary = models.CharField(max_length=3072, blank=True) >> origin = models.CharField(max_length=96, blank=False) >> # more stuff >> >> # taskmgr/urls.py >> from django.conf.urls.defaults import * >> from django.views.generic import list_detail >> from mysite.taskmgr.models import Task >> >> urlpatterns = patterns('taskmgr.views', >> url(r'^$', list_detail.object_list, { "queryset" : >> Task.objects.all() }, name="task_list"), >> # more urls >> >> # task_list.html >> >> This is the task list >> {% for object in Task.object.all %} >> {{ object.id }} -- {{ object.name }} is due: >> {{ object.date_comp_req }} >> {% endfor %} >> >> >> >> I know it is picking up the template, because it displays the text in >> the line But it displays nothing else. >> >> If I do this in the shell: >> >p = Task.objects.get(pk=1) >> [, ] >> >p.name >> u'Build Task Manager' >> >> So I know that Task.objects gets me something... What do I need to >> change to pass this to the template properly... >> >> >> > >> > > > > -- Justin Lilly Python/Django Developer http://justinlilly.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: Problem with generic views
task_list not Task.object.all in the view. 2009/6/27 Technicalbard: > > Hey all, > > I did the tutorial, yet when I try to apply what I've learned (or > think I've learned), to my own application it doesn't work... > > My code looks like this: > > # taskmgr/models.py > class Task(models.Model): > name = models.CharField(max_length=216) > summary = models.CharField(max_length=3072, blank=True) > origin = models.CharField(max_length=96, blank=False) > # more stuff > > # taskmgr/urls.py > from django.conf.urls.defaults import * > from django.views.generic import list_detail > from mysite.taskmgr.models import Task > > urlpatterns = patterns('taskmgr.views', > url(r'^$', list_detail.object_list, { "queryset" : > Task.objects.all() }, name="task_list"), > # more urls > > # task_list.html > > This is the task list > {% for object in Task.object.all %} > {{ object.id }} -- {{ object.name }} is due: > {{ object.date_comp_req }} > {% endfor %} > > > > I know it is picking up the template, because it displays the text in > the line But it displays nothing else. > > If I do this in the shell: > p = Task.objects.get(pk=1) > [, ] > p.name > u'Build Task Manager' > > So I know that Task.objects gets me something... What do I need to > change to pass this to the template properly... > > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Problem with generic views
Hey all, I did the tutorial, yet when I try to apply what I've learned (or think I've learned), to my own application it doesn't work... My code looks like this: # taskmgr/models.py class Task(models.Model): name = models.CharField(max_length=216) summary = models.CharField(max_length=3072, blank=True) origin = models.CharField(max_length=96, blank=False) # more stuff # taskmgr/urls.py from django.conf.urls.defaults import * from django.views.generic import list_detail from mysite.taskmgr.models import Task urlpatterns = patterns('taskmgr.views', url(r'^$', list_detail.object_list, { "queryset" : Task.objects.all() }, name="task_list"), # more urls # task_list.html This is the task list {% for object in Task.object.all %} {{ object.id }} -- {{ object.name }} is due: {{ object.date_comp_req }} {% endfor %} I know it is picking up the template, because it displays the text in the line But it displays nothing else. If I do this in the shell: >>>p = Task.objects.get(pk=1) [, ] >>>p.name u'Build Task Manager' So I know that Task.objects gets me something... What do I need to change to pass this to the template properly... --~--~-~--~~~---~--~~ 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: problem with generic views (monthly archive) and different languages
URL keyed off of numeric month instead of localized name. -Nathan On Sat, Sep 13, 2008 at 6:02 AM, Julian <[EMAIL PROTECTED]> wrote: > > hi there, > > in my settings.py there is the language specified as "de_de", wich > works well with things like: > > {{{ > blog_entry.timestamp|date:"b" > }}} > > in may, it returns "Mai", wich is german for may. > > but i am using the generic views for my blog archive, and monthly > based i'm doing things like: > > {{{ > month=previous_month|date:"b"|lower %}">Vorheriger Monat > }}} > > but i receiven an url like: > > blog/2008/mai/ > > wich turns into an 404 error page, because in this case it should be > blog/2008/may > > what's a solution for my problem? > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
problem with generic views (monthly archive) and different languages
hi there, in my settings.py there is the language specified as "de_de", wich works well with things like: {{{ blog_entry.timestamp|date:"b" }}} in may, it returns "Mai", wich is german for may. but i am using the generic views for my blog archive, and monthly based i'm doing things like: {{{ Vorheriger Monat }}} but i receiven an url like: blog/2008/mai/ wich turns into an 404 error page, because in this case it should be blog/2008/may what's a solution for my problem? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with generic views in tutorial example
> Anurag, Thanks. That worked for me too. But it's hardly a solution. > Now I can't use admin. I want both. Is that asking too much? Has > anyone else any ideas? OK, I've solved all my problems. It was my mistake. For some reason, I had these two lines in urls.py in the reverse order: (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/(.*)', admin.site.root), Now I can have a public and admin interface, whether or not I use a separate admin.py file. Sorry to have bothered you. It seems generic views work after all! But it was useful for me to learn about admin.py - it seems a good idea to use a separate admin.py file. Rodney --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with generic views in tutorial example
And in my first reply, I meant 'mysite/polls/urls.py' when I said: ' . I did however, do something that the tutorial did not ask to do - i.e. delete all references to the admin in mysite/urls.py, which looks like this ' On Aug 22, 1:38 am, Rodney Topor <[EMAIL PROTECTED]> wrote: > On Aug 22, 4:18 pm, Anurag Goel <[EMAIL PROTECTED]> wrote:> I was able to > implement the generic views change with yesterday's > > trunk version successfully. I did not have to do anything special (no > > separate admin.py, no get_absolute_url()) > > > I did however, do something that the tutorial did not ask to do - i.e. > > delete all references to the admin in mysite/urls.py, which looks like > > this: > > Anurag, Thanks. That worked for me too. But it's hardly a solution. > Now I can't use admin. I want both. Is that asking too much? Has > anyone else any ideas? > > > On Aug 21, 10:45 pm, Rodney Topor <[EMAIL PROTECTED]> wrote: > > > > I'm having trouble modifying the tutorial example to use generic > > > views. (My implementation without generic views works fine.) I've > > > registered the class Poll with admin in a separate admin.py module as > > > described in ticket 8181. I've provided names for all url patterns in > > > app polls. I've defined get_absolute_url() for class Poll using the > > > name for the poll detail pattern. I've implemented view vote() as > > > described in the tutorial, Yet when I cast a vote in the form with > > > action = /polls/n/vote/, I get the following error: > > > > The model Poll is already registered > > > > Any suggestions? > > > > (And this is separate from the reverse lookup failures I get with > > > generic views using named patterns in url template tags...) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with generic views in tutorial example
Apologies - I did not mention that my original urls.py (under mysite/, at the same level as polls/) still exists (the urls.py has to be copied over as opposed to moved), and it contains the following code: --mysite/urls.py begin-- from django.conf.urls.defaults import * # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('mysite.polls.views', #enables admin and poll/urls.py (r'^polls/', include('mysite.polls.urls')), (r'^admin/(.*)', admin.site.root), ) --end mysite/urls.py-- Again, no need for any additional changes. On Aug 22, 1:38 am, Rodney Topor <[EMAIL PROTECTED]> wrote: > On Aug 22, 4:18 pm, Anurag Goel <[EMAIL PROTECTED]> wrote:> I was able to > implement the generic views change with yesterday's > > trunk version successfully. I did not have to do anything special (no > > separate admin.py, no get_absolute_url()) > > > I did however, do something that the tutorial did not ask to do - i.e. > > delete all references to the admin in mysite/urls.py, which looks like > > this: > > Anurag, Thanks. That worked for me too. But it's hardly a solution. > Now I can't use admin. I want both. Is that asking too much? Has > anyone else any ideas? > > > On Aug 21, 10:45 pm, Rodney Topor <[EMAIL PROTECTED]> wrote: > > > > I'm having trouble modifying the tutorial example to use generic > > > views. (My implementation without generic views works fine.) I've > > > registered the class Poll with admin in a separate admin.py module as > > > described in ticket 8181. I've provided names for all url patterns in > > > app polls. I've defined get_absolute_url() for class Poll using the > > > name for the poll detail pattern. I've implemented view vote() as > > > described in the tutorial, Yet when I cast a vote in the form with > > > action = /polls/n/vote/, I get the following error: > > > > The model Poll is already registered > > > > Any suggestions? > > > > (And this is separate from the reverse lookup failures I get with > > > generic views using named patterns in url template tags...) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with generic views in tutorial example
On Fri, Aug 22, 2008 at 4:38 AM, Rodney Topor <[EMAIL PROTECTED]> wrote: > > On Aug 22, 4:18 pm, Anurag Goel <[EMAIL PROTECTED]> wrote: > > I was able to implement the generic views change with yesterday's > > trunk version successfully. I did not have to do anything special (no > > separate admin.py, no get_absolute_url()) > > > > I did however, do something that the tutorial did not ask to do - i.e. > > delete all references to the admin in mysite/urls.py, which looks like > > this: > > > Anurag, Thanks. That worked for me too. But it's hardly a solution. > Now I can't use admin. I want both. Is that asking too much? Has > anyone else any ideas? > Your urls.py file should have admin.autodiscover(). You should not have any admin.site.register calls for Poll except for what you have in the admin.py you created. The duplicate registration message you get makes it sound like you have another registration getting called from somewhere. Did you not remove it from models.py when you created admin.py? Karen > > > On Aug 21, 10:45 pm, Rodney Topor <[EMAIL PROTECTED]> wrote: > > > > > I'm having trouble modifying the tutorial example to use generic > > > views. (My implementation without generic views works fine.) I've > > > registered the class Poll with admin in a separate admin.py module as > > > described in ticket 8181. I've provided names for all url patterns in > > > app polls. I've defined get_absolute_url() for class Poll using the > > > name for the poll detail pattern. I've implemented view vote() as > > > described in the tutorial, Yet when I cast a vote in the form with > > > action = /polls/n/vote/, I get the following error: > > > > > The model Poll is already registered > > > > > Any suggestions? > > > > > (And this is separate from the reverse lookup failures I get with > > > generic views using named patterns in url template tags...) > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with generic views in tutorial example
On Aug 22, 4:18 pm, Anurag Goel <[EMAIL PROTECTED]> wrote: > I was able to implement the generic views change with yesterday's > trunk version successfully. I did not have to do anything special (no > separate admin.py, no get_absolute_url()) > > I did however, do something that the tutorial did not ask to do - i.e. > delete all references to the admin in mysite/urls.py, which looks like > this: > Anurag, Thanks. That worked for me too. But it's hardly a solution. Now I can't use admin. I want both. Is that asking too much? Has anyone else any ideas? > On Aug 21, 10:45 pm, Rodney Topor <[EMAIL PROTECTED]> wrote: > > > I'm having trouble modifying the tutorial example to use generic > > views. (My implementation without generic views works fine.) I've > > registered the class Poll with admin in a separate admin.py module as > > described in ticket 8181. I've provided names for all url patterns in > > app polls. I've defined get_absolute_url() for class Poll using the > > name for the poll detail pattern. I've implemented view vote() as > > described in the tutorial, Yet when I cast a vote in the form with > > action = /polls/n/vote/, I get the following error: > > > The model Poll is already registered > > > Any suggestions? > > > (And this is separate from the reverse lookup failures I get with > > generic views using named patterns in url template tags...) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with generic views in tutorial example
I was able to implement the generic views change with yesterday's trunk version successfully. I did not have to do anything special (no separate admin.py, no get_absolute_url()) I did however, do something that the tutorial did not ask to do - i.e. delete all references to the admin in mysite/urls.py, which looks like this: --begin-- from django.conf.urls.defaults import * from mysite.polls.models import Poll info_dict = { 'queryset': Poll.objects.all(), } urlpatterns = patterns('', (r'^$', 'django.views.generic.list_detail.object_list', info_dict), (r'^(?P\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict), url(r'^(?P\d+)/results/$', 'django.views.generic.list_detail.object_detail', dict(info_dict, template_name='polls/ results.html'), 'poll_results'), (r'^(?P\d+)/vote/$', 'mysite.polls.views.vote'), ) --end-- Hope this helps. -Anurag On Aug 21, 10:45 pm, Rodney Topor <[EMAIL PROTECTED]> wrote: > I'm having trouble modifying the tutorial example to use generic > views. (My implementation without generic views works fine.) I've > registered the class Poll with admin in a separate admin.py module as > described in ticket 8181. I've provided names for all url patterns in > app polls. I've defined get_absolute_url() for class Poll using the > name for the poll detail pattern. I've implemented view vote() as > described in the tutorial, Yet when I cast a vote in the form with > action = /polls/n/vote/, I get the following error: > > The model Poll is already registered > > Any suggestions? > > (And this is separate from the reverse lookup failures I get with > generic views using named patterns in url template tags...) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Problem with generic views in tutorial example
I'm having trouble modifying the tutorial example to use generic views. (My implementation without generic views works fine.) I've registered the class Poll with admin in a separate admin.py module as described in ticket 8181. I've provided names for all url patterns in app polls. I've defined get_absolute_url() for class Poll using the name for the poll detail pattern. I've implemented view vote() as described in the tutorial, Yet when I cast a vote in the form with action = /polls/n/vote/, I get the following error: The model Poll is already registered Any suggestions? (And this is separate from the reverse lookup failures I get with generic views using named patterns in url template tags...) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with generic views (404)
On 9/16/07, Florian Lindner <[EMAIL PROTECTED]> wrote: > {% if Abbreviation_list %} Read the generic views documentation carefully; the default variable name the view will give you is "object_list". -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with generic views (404)
Am Sonntag, 16. September 2007 schrieb Collin Grady: > Do you actually have any Abbreviation objects? > > If you don't tell the view to allow empty results, it'll 404 if it has > nothing to show :) Yes, this was the problem, thanks! However I ran into the next problem just 5 minutes later. I have an template that is used for this generic view: {% if Abbreviation_list %} {% for abbr in Abbreviation_list %} {{ abbr.abbreviation }} {% endfor %} {% else %} No abbreviations are available. {% endif %} That just gives: "No abbrevations...". If I remove the if clause there is just in the HTML source code. But there are objects: [EMAIL PROTECTED] ~/xgm $ ./manage.py shell Python 2.4.4 (#1, May 13 2007, 13:02:35) [GCC 4.1.1 (Gentoo 4.1.1-r3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from xgm.AbbrDB.models import * >>> Abbreviation.objects.all() [, ] Everything is unchanged compared to my previous post. Thanks, Florian --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with generic views (404)
Do you actually have any Abbreviation objects? If you don't tell the view to allow empty results, it'll 404 if it has nothing to show :) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Problem with generic views (404)
Hello, I have an problem using generic views. My settings.py has set: TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.load_template_source', 'django.template.loaders.app_directories.load_template_source', ) TEMPLATE_DIRS = ("/home/florian/xgm/templates/", ) I have an app AbbrDB which has an url.py: info_dict = { "queryset": Abbreviation.objects.all(), } urlpatterns = patterns("xgm.AbbrDB.views", (r"^$", "search"), ) urlpatterns += patterns("", (r'^list/$', 'django.views.generic.list_detail.object_list', info_dict), ) This url.py is included from the projects url.py like that: (r"^abbr/", include("xgm.AbbrDB.urls")) The search view works perfect but the generic view does not. I have an template called Abbreviation_list.html in ~/xgm/AbbrDB/templates/. It contains only "TEST!" at the moment. The URL http://localhost:8000/abbr/list/ only gives an 404 error: Request Method: GET Request URL: http://localhost:8000/abbr/list/ It does NOT complains about not found an suitable regexp like that: Using the URLconf defined in xgm.urls, Django tried these URL patterns, in this order: As far as I understand the generic view object_list should look for a template called Abbreviation_list.html. Since app_directories.load_template_source template loader is loaded it looks for this template in AppDir/templates/ But what's wrong? Thanks, Florian --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---