Ok thanks for the help so far. I've gotten the hang of how to use the
create/update/delete generic views. My problem now happens when I try
to use the display a form for a particular league. My home page lists
all the leagues. For simplicity, we'll say there's a men's league and
a women's league displayed on the homepage. When I click on either of
these, I want to be taken to the form that signs one up for that
particular league. My models.py is set up as follows:

from django.db import models
from django.forms import ModelForm

class League(models.Model):
    league_name = models.CharField(max_length=100)
    pub_date = models.DateTimeField('date published')

class Info(models.Model):
    league = models.ForeignKey(League)
    name = models.CharField(max_length=50)
    phone = models.IntegerField()
    email = models.EmailField()
    def __unicode__(self):
        return self.info

class InfoForm (ModelForm):
    class Meta:
        model = Info
        exclude = ('league')

My urls.py file is set up as follows:

from django.conf.urls.defaults import *
from mysite.player_info.models import League, Info, InfoForm

info_dict = {
    'queryset': League.objects.all(),
}

InfoForm = {'form_class' : InfoForm}

urlpatterns = patterns('',
    (r'^$', 'django.views.generic.list_detail.object_list',
info_dict),
    (r'^(?P<object_id>\d+)/$',
'django.views.generic.list_detail.object_detail', info_dict),
    url(r'^(?P<object_id>\d+)/results/$',
'django.views.generic.list_detail.object_detail', dict(info_dict,
template_name='player_info/results.html'), 'league_results'),
    (r'^(?P<league_id>\d+)/signup/$',
'mysite.player_info.views.signup'),
    (r'^(?P<object_id>\d+)/info/create/$',
'django.views.generic.create_update.create_object', InfoForm),
)

So now, back to the homepage... when I click on the league, I get a
TypeError: create_object() got an unexpected keyword argument
'object_id' because my href is set up like so: <a href="/league/
{{ object.id }}/info/create/"> {{ object.league_name }} </a>.

My question is how to display my form so that a player can sign up for
a particular league without signing up for all leagues. Did I mess up
in setting up my models (in other words, should League and Info be
seperate tables or one big table?) or is the problem with how I set up
my urls?
On Oct 31, 6:45 pm, Mike Ramirez <[email protected]> wrote:
> On Saturday 31 October 2009 15:34:07 Ross wrote:
>
> > I'm new to Django and web programming in general and I'm trying to
> > write a simple page that will allow users to sign up for different
> > leagues. The sign up form will have multiple fields (name, phone,
> > address, etc). I've read over the forms documentation and the
> > modelforms documentation, but I'm still confused over when I should
> > use one or the other. I'm confused because it seems to me that since
> > any form where a user enters information commits that info to the
> > database, why wouldn't I always use ModelForm.Lastly, as a side-
> > question, can either of these be used in conjunction with generic
> > views, or must I write my own?
>
> You can use generic views[1] and it is suggested you use modelforms with
> create/update/delete views. Model forms and forms do the same thing, just
> forms doesn't know the model to use and you need to manually define the
> fields, model form knows the model and builds your form, based on how you set
> up your model form class and model.
>
> When you wouldn't want to use model forms, is probably when you're using
> fields that aren't in the model, like a captcha field. Though, I woud suggest
> just using model forms, then when you run into that situation where model
> forms aren't enough, then build a form.
>
> Mike
>
> [1]http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-
> generic-create-update-create-object
> --
> I hope the ``Eurythmics'' practice birth control ...
>
>  signature.asc
> < 1KViewDownload
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to