On Oct 28, 2:47 pm, Robert Dailey <[EMAIL PROTECTED]> wrote:
> On Oct 28, 11:17 am, Steve Holden <[EMAIL PROTECTED]> wrote:
>
>
>
> > Robert Dailey wrote:
> > > On Oct 28, 10:29 am, Steve Holden <[EMAIL PROTECTED]> wrote:
>
> > >> Robert Dailey wrote:
>
> > >>> Hi,
>
> > >>> I currently have the following model:
>
> > >>> class Note( models.Model ):
> > >>>    content = models.TextField()
>
> > >>> I've setup the admin page to allow users to add "notes", which
> > >>> basically lets them fill in the content variable. However, on the
> > >>> admin page I want to add a column to show the user that added that
> > >>> note. This would be the username in the admin page that they logged in
> > >>> with. I hope that I can do this without adding any information to my
> > >>> Note class, but if I must then I don't mind.
>
> > >>> So column 1 should be the user that added that note, and Column 2
> > >>> should be the note itself.
>
> > >> The usual way to do this is to establish a relationship between User and
> > >> Note. Since each note will only be created by a single user, and each
> > >> user can (presumably) issue many notes the sensible thing to do would be
> > >> to add a foreign key to Note to express which user created it.
>
> > >> OK, assuming you can import your User model into the module that defines
> > >> your Note model, you would just need to add
>
> > >>     user = models.ForeignKey(User)
>
> > >> to the Note model.
>
> > > Thanks for your help. I tried the following:
>
> > > from django.db import models
> > > from django.contrib.auth.models import User
>
> > > # Create your models here.
> > > class Note( models.Model ):
> > >    content = models.TextField()
> > >    user = models.ForeignKey( User )
>
> > > However, now when I visit the page that lists my notes, I get the
> > > following error:
>
> > > OperationalError at /admin/core/note/
> > > (1054, "Unknown column 'core_note.user_id' in 'field list'")
>
> > > Any idea what is going on?
>
> > You'll need to add the corresponding field to your database. If you
> > don't have any data worth keeping on the Note table (it will be called
> > YourappnameNote in the database) then the easiest thing to do is delete
> > the whole table then run
>
> >   python manage.py syncdb
>
> > to re-create the table with the additional field.
>
> Awesome, thank you!
>
> I'm have some more questions for you if you don't mind. When I add a
> note, now there is a combo box with a list of users to choose from. I
> would like for this combo box to not be visible and for it to
> automatically choose the user submitting the note (The user currently
> logged in). Is there a way to do this?

Bump

Any ideas on this?
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to