I am using Django's ModelForm in a template im working on. I am trying
to use it to display the Django User Object and an extension I added
of the user model, what would be the correct way to display my User
model extension in my template, I would like to be able to edit the
User information and the account number I have added all from the same
form. Thanks.
class UserModelForm(forms.ModelForm):
class Meta:
model = User
fields = ('username','first_name','last_name',
'password_field','email','account','is_superuser','is_staff')
@staff_member_required
def create_edit_users(request, id=None):
user = request.user
tick_num = Ticket.objects.filter(status__contains='Open').count()
if id is not None:
puser = get_object_or_404(User, pk=id)
else:
puser = None
form = UserModelForm(data=request.POST or None, instance=puser)
if form.is_valid():
form.save()
return HttpResponseRedirect("/users/")
return render_to_response("user.php", {'form':form},RequestContext
(request))
My extension of the User model is as follows
class Account_Number(models.Model):
account_number = models.CharField(max_length=8)
user = models.ForeignKey(User, unique=True)
userfield = models.NullBooleanField(null=True, blank=True)
def __str__(self):
return self.account_number
class Admin:
list_display = ('account_number','userfield')
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---