I would suggest overriding the User's ModelForm and adding you validation as
per any method here:
https://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#validating-objects
Here is a sample code I use for UserProfile myself:
http://dpaste.com/734257/
Hope that helps.
From: Oscar Mederos
Sent: Thursday, April 19, 2012 7:24 AM
To: django-users@googlegroups.com
Subject: Force the user to add an instance of some InlineModelAdmin when
adding a model
I have a UserAdmin, and I defined a UserProfileInline like this:
-------------
from ...
from django.contrib.auth.admin import UserAdmin as UserAdmin_
class UserProfileInLine(admin.StackedInline):
model = UserProfile
max_num = 1
can_delete = False
verbose_name = 'Profile'
verbose_name_plural = 'Profile'
class UserAdmin(UserAdmin_):
inlines = [UserProfileInLine]
-------------
My UserProfile model has some required fields.
What I want is to force the user not only to enter the username & repeat
password, but also to enter at least the required fields so that the
UserProfile instance is created and associated to the User that is being
added.
If I enter anything in any field of UserProfileInline when creating the
user, it validates the form without problem, but if I don't touch any field,
it just creates the User and nothing happens with the UserProfile.
Any thoughts?
Thanks in advance.
--
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+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
Daniel Sokolowski
Web Engineer
KL Insight
http://klinsight.com/
Tel: 613-344-2116 | Fax: 613.634.7029
993 Princess Street, Suite 212
Kingston, ON K7L 1H3, Canada
Notice of Confidentiality:
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. Any review re-transmission dissemination or other use of or taking
of any action in reliance upon this information by persons or entities other
than the intended recipient is prohibited. If you received this in error
please contact the sender immediately by return electronic transmission and
then immediately delete this transmission including all attachments without
copying distributing or disclosing same.
--
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+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.