Please forgive me if this is a stupid question, but I haven't been
able to find a good answer searching! Doesn't help that I'm only a
few weeks acquainted with both both Django and Python. I'm
definitely liking it so far.
Anyway, I've got a custom user model with several required foreign
keys. I need to have a form that only displays a subset of the model
fields, and the required keys are not in this subset! That leads to
problems with trying to save the form generated by form_for_model().
class CustomUser(model.Models)
client = models.ForeignKey(Client)
agent = models.ForeignKey(Agent)
type = models.ForeignKey(LeadType,null=True)
site = models.ForeignKey(ClientSite,null=True)
firstname = models.CharField(blank=True, maxlength=64)
lastname = models.CharField(blank=True, maxlength=64)
email = models.CharField(blank=True, maxlength=64)
phone = models.CharField(blank=True, maxlength=12)
...
---- then in the view I've got ----
def CustomUser_callback(form, **kwargs):
display_fields = ('firstname', 'lastname', 'email', 'phone')
if form.name in display_fields:
return form.formfield(**kwargs)
else:
return None
...
RegistrationForm = forms.form_for_model(CustomUser,
formfield_callback=CustomUser_callback)
myform = RegistrationForm(request.POST)
myform.save() # This won't work because the required foreign keys
client, and agent are not set
----
The form display is exactly what I need, showing only the fields
listed in display_fields, but I can't figure out how I should specify
the client and agent keys (which are known to the view) to allow the
form to save.
I thought about creating a CustomUser(), setting the fields and just
using the model to save... but it just doesn't seem like that should
be the 'right' way, even if it works. Any pointers or suggestions
would be most appreciated.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---