Thursday, September 29, 2011

Re: Help with forms (really struggling)

Hey,

I'm still half asleep so I apologize if this is a dumb question. Is the "Person" the User using this? If so, you should have access to the User object from the session.
If not, you could probably do a query with the Primary Key to grab the Person object.

e.g.

person = Person.objects.get(pk = some_integer)
log = Log(person = person, ...)

Hopefully that helps a little bit.

On Thu, Sep 29, 2011 at 6:29 AM, David <cthlogs@gmail.com> wrote:
Hi

I have a page called Person which lists basic contact details. I
intend to have a series of forms on this page in hidden div's that
enable a user to submit data pertaining to this contact such as
contact logs. Each form will be submitted by ajax which is why I am
making their form actions point at a different view than that which
makes the Person page.

To use the Contact Log as an example the model is:

class Log(models.Model):
   person = models.ForeignKey(Person)
   user = models.ForeignKey(User, verbose_name="team member")
   contact_date = models.DateTimeField(auto_now_add=True)
   contact_detail = models.TextField()
   modification_date = models.DateTimeField(auto_now=True)

   class Meta:
       ordering = ['-contact_date', '-modification_date',]

I am using ModelForm to show this on my Person page, but am hiding the
following fields:

person
user
contact_date
modification_date

This is because what I would like is for there to be a simple textarea
that a user can fill in and on submit things like person and user
should be passed through the form submission.

When I then make my view to process the form I have tried using
commit=false and then adding the person and user in prior to save but
because I am passing person as an integer and not an instance of
person my save fails.

Can anyone give me any ideas to resolve this? Or tutorials that deal
with something similar?

Thank you

--
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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment