0

....

from django.contrib.auth.models import User

class Person(models.Model):
    user = models.OneToOneField(User)
    avatar = models.ImageField(upload_to="photos/")
    level = models.IntegerField(default=0)

    def __unicode__(self):
        return u"%s" % self.user

I'd like to add an edit-person page where the user can modify his profile if he wants to. So I created not only a form for the model Person but also another one for the django model User so that the user can modify information such as username, last_name, first_name, email etc

I'm not proud of the way I did it although it works well. So my question is: Is there a way that I can "explode" the django User field which is in my Person model instead of having a select list in my client side?

karthikr
  • 97,368
  • 26
  • 197
  • 188
smarber
  • 4,829
  • 7
  • 37
  • 78
  • Yes. you can do 1 of 2 things - Customized user model, or add those fields in the form, so user can enter the details as a flat form. – karthikr Apr 08 '14 at 17:26
  • thanks for your awnser. Customizing user model will certainly be very painful because my database is pretty big. Could you tell me more about how can I add fields of User into form? Did you mean that I cannot use ModelForm in my case?Form instead? how ? – smarber Apr 08 '14 at 21:26
  • 1
    You can still use a modelform. Here is how you could add more fields: http://stackoverflow.com/questions/13550515/django-add-extra-field-to-a-modelform-generated-from-a-model – karthikr Apr 19 '14 at 03:44

0 Answers0