I am falling in love with Django but it is quite challenging to lern
django and python at the same time. I am not quite getting this.
1) I know I can do new_form.errors and I can see the errors in a shell
but how do they go back to the template?
2) When I do PeopleOrgUser.objects.get(user_id = 1, role=1) I get the
error "Cannot resolve keyword 'user_id' into field" I have a feeling I
had solved this somewhere else before but can't find it. It has
something to do with well user_id is a ForeignKey field.
=== This is what I got so far ===
def person(request):
#obj_pou = PeopleOrgUser.objects.get(role=1)
People.objects.all()
PeopleForm = form_for_model(People)
if request.method == 'POST':
edit_form = PeopleForm(request.POST)
if edit_form.is_valid():
person = People(**edit_form.clean_data)
person.save()
pou {}
pou['person_id'] = person.id
pou['user_id'] = request.user.id
pou['role'] = 1
pou.save()
return HttpResponseRedirect("/accounts/person/")
else:
edit_form = PeopleForm()
return render_to_response('accounts/people_form.html',
{'form': PeopleForm, 'printform': edit_form})
else:
# No POST, so we want a brand new form without any data or
errors.
errors = new_data = {}
edit_form = PeopleForm()
return render_to_response('accounts/people_form.html', {'form':
PeopleForm, 'printform': edit_form})
==========TEMPLATE===========
{% block content %}
<form method="post" action="">
<fieldset class="module aligned"><legend>Profile</legend>
<table>
{{ printform }}
</table>
</fieldset>
<div class="submit-row">
{% if form.manipulator.change %}
<a href="{{ redirect_to }}" class="deletelink">Cancel</a>
<input type="submit" value="Save" class="default" />
{% else %}
<input type="submit" value="Create" class="default" />
{% endif %}
</div>
</form>
{% endblock %}
======= SQL ========
CREATE TABLE "data_people" (
"id" integer NOT NULL PRIMARY KEY,
"fname" varchar(30) NOT NULL,
"mname" varchar(30) NOT NULL,
"lname" varchar(30) NOT NULL,
"address_id" integer NULL REFERENCES "data_addressbook" ("id")
);
CREATE TABLE "data_peopleorguser" (
"id" integer NOT NULL PRIMARY KEY,
"person_id" integer NOT NULL REFERENCES "data_people" ("id"),
"org_id" integer NOT NULL,
"user_id" integer NOT NULL REFERENCES "auth_user" ("id"),
"role" smallint unsigned NOT NULL
);
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---