The people and publication are not related so I cant use manytomany

On 31 Mart, 15:30, "Giovannetti, Mark" <mark.giovanne...@nrcan-
RNCan.gc.ca> wrote:
> > I am entering them on the same page otherwise I will have to note down
> > the ids of people and publications table and then go to bridge table
> > and insert the ids there. So the reason I want to enter in the same
> > page is I will insert the ids into bridge table whenever I click save.
> > I am not allowed to change the db design by the way and it sucks :)
>
> Does this not work the way you expect?
>
> class People(models.Model):
>
>     .... other fields
>
>     publications = models.ManyToManyField('Publication',
>                                     through='PeoplePublication',
>                                     )
>
> class Publication(models.Model):
>
>     .... other fields
>
> class PeoplePublication(models.Model):
>
>     people = models.ForeignKey('People',...)
>     publication = models.ForeignKey('Publication',...)
>
> in admin.py:
>
> class PublicationInline(admin.TabularInline):
>     model = PeoplePublication
>     extra = 1
>
> class PeopleAdmin(admin.ModelAdmin):
>     inlines = [PublicationInline]
>
> admin.site.register(People, PeopleAdmin)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to