On Mon, Mar 9, 2009 at 10:57 AM, mike171562 <support.desk....@gmail.com>wrote:
> > To display and edit my extension of the user model in the admin > interface I simply add > > class Admin: > list_display = ('account_number','userfield') > > how can i get this to display in my ModelForm fields? > > > > > > On Mar 9, 10:51 am, mike171562 <support.desk....@gmail.com> wrote: > > Thanks alex, that worked, I have the extra field, and now to figure > > out how to to tie it in to the main form and my user model. > > > > On Mar 9, 10:12 am, Alex Gaynor <alex.gay...@gmail.com> wrote: > > > > > On Mon, Mar 9, 2009 at 10:10 AM, mike171562 < > support.desk....@gmail.com>wrote: > > > > > > thanks malcolm, thats doesnt seem to work though > > > > > > class UserModelForm(forms.ModelForm): > > > > class Meta: > > > > model = User > > > > account = forms.CharField(max_length=50) > > > > fields = > > > > ('username','email','first_name','last_name','account') > > > > adding the 'account' field as extra is not displayed in the ((field)) > > > > form in the template. > > > > > > On Mar 6, 8:40 pm, Malcolm Tredinnick <malc...@pointy-stick.com> > > > > wrote: > > > > > On Fri, 2009-03-06 at 12:25 -0800, mike171562 wrote: > > > > > > 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. > > > > > > > A Django Form object represents only a part of an HTML form (which > is > > > > > why need to write the HTML "form" tag in the template, for > example). You > > > > > can pass multiple form objects through from your view function to > the > > > > > template and render both of them inside the same HTML form. > > > > > > > If you want to intermingle fields, you can define extra form fields > on a > > > > > model form. For example: > > > > > > > class MyForm(forms.ModelForm): > > > > > extra = forms.CharField(max_length=50) > > > > > > > class Meta: > > > > > model = models.Tag > > > > > > > That will put the extra fields at the end of the model form. > > > > > > > If you want to put the extra fields in the middle of the model > fields > > > > > somehow, you can either write a custom __init__ method to tweak the > > > > > field ordering (you'll have to read the forms code a bit to see > what > > > > > needs tweaking). Alternatively, you can take the not unreasonable > > > > > approach that you've gone beyond the scope of modelforms by this > point > > > > > and just write a normal Form class that contains the fields. > > > > > > > I've always been an interested observer of people trying to make > > > > > automatic model-related forms do all sorts of funky things, because > I > > > > > hardly ever use them. So many of my use-cases don't have forms > mapping > > > > > directly to models, so I write a normal Form class and then my view > > > > > knows how to take fields from the Form instance and convert that > data to > > > > > the appropriate models. At some point, it's a fairly grief-free way > to > > > > > handle anything beyond the straight model -> form -> model > conversion. > > > > > But, as you can see from the above, you aren't short of options > here. > > > > > > > Regards, > > > > > Malcolm > > > > > The account = part shouldn't be in the inner Meta class. > > > > > Alex > > > > > -- > > > "I disapprove of what you say, but I will defend to the death your > right to > > > say it." --Voltaire > > > "The people's good is the highest law."--Cicero > > > Look at the fields options on the ModelAdmin: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#fields or the form option if you want to supply your own form class. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---