views:

43

answers:

1

I have a projects page where users can start up new projects. Each project has two forms.

The two forms are:

class ProjectForm(forms.Form):
Title = forms.CharField(max_length=100, widget=_hfill)

class SsdForm(forms.Form):
Status = forms.ModelChoiceField(queryset=P.ProjectStatus.objects.all())

With their respective models as follows:

class Project(DeleteFlagModel):
Title = models.CharField(max_length=100)

class Ssd(models.Model):
Status = models.ForeignKey(ProjectStatus)

Now when a user fills out these two forms, the data is saved into the database. What I want to do is access this data and generate it onto a new URL. So I want to get the "Title" and the "Status" from these two forms and then show them on a new page for that one project. I don't want the "Title" and "Status" from all the projects to show up, just for one project at a time. If this makes sense, how would I do this?

I'm very new to Django and Python (though I've read the Django tutorials) so I need as much help as possible.

Thanks in advance

Edit:

The ProjectStatus code is (under models):

class ProjectStatus(models.Model):
Name = models.CharField(max_length=30)
def __unicode__(self):
return self.Name
+1  A: 

You don't seem to have any relationship between Project and SSD. Without that, there's no way of telling that any particular SSD object is a member of a particular project. I presume that there are other fields on these models, otherwise there's no point in having SSD as a separate model - status should just be a field on the Project model.

But once you've got a relationship between Project and SSD, you can just get the project and then show its related SSD objects in one go by using the relationship:

proj = Project.objects.get(pk=myvalue)
for ssd in proj.ssd_set.all():
     print ssd.Status

Also, those forms are plain forms, instead of ModelForms. What happens to the data in them? If they were modelforms, you could save it by just calling form.save().

Daniel Roseman