def CustomUser_callback(field, **kwargs):
    display_fields = ('firstname', 'lastname', 'email', 'phone')
    if field.name in display_fields:
        return field.formfield(**kwargs)
    else:
        return None

After looking at the django source, I realized that the 'f' was for
field, not form.  I didn't want other noob reading this to make the
same mistake I did when I tried to clarify the code by replacing 'f'
with 'form'.  Above it what it should be.  Now I remember why one of
my comp-sci profs didn't like one letter variable names.

After doing some more searching, I saw one post in the newsgroup that
simple added values to form.clean_data right before trying form.save()

so I tried:

myform.clean_data['client'] = request.site.client
myform.clean_data['agent'] = 1 # just to see if it would work

Some progress, I get a different failure.  Now I fail on the next
field in the CustomUser table, which is not required, not a key, and
not wanted in the form.  This table as 20 or so fields, does this mean
I have to specify each one for save() to work?  I had assumed that for
an insert/update it would only need the required fields.  Considering
how elegant the rest of django is, I've come to the conclusion it's
definitely me that's the problem here.

So how would you approach:
1) Model with 20+ fields, most defaulting to null
2) A user form for that with at most 4 fields visible, and the values
for the two required keys specified in the view.

Would this be a better way?

user = CustomUser()
user.firstname = myform.clean_data['firstname']
user.lastname = myform.clean_data['firstname']
user.email = myform.clean_data['email']
user.phone = myform.clean_data['phonel']
user.client = request.site.client  # I've got custom middleware that
adds a site instance to the request
user.site = request.site.id
user.agent = request.site.agent
user.save()




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to