django - create a model that lets you insert multiple values for the same field? -


ok i'm trying should simple in mind missing sql or django admin knowledge it. have simple model such

class book(models.model):     title = models.charfield(max_length = 50)     review = models.textfield() 

and want 'review' field in admin site have little plus sign add more reviews same model instance template iterate through them.

i know create m2m field reviews , give me that, rather reviews filled same page without popups (for helpless users keep wsiwyg possible, since textfields tinymce powered), , wonder if it's necessary create model textfield

create review model holds review text , has foreignkey book...

class book(models.model):    title = models.charfield()  class review(models.model):    book = models.foreignkey(book, related_name='reviews')    review = models.textfield() 

...then register appropriate type of inlinemodeladmin edit related reviews on book's page in admin. i'd suggest using stackedinline in case:

class reviewinline(admin.stackedinline):     model = review  class bookadmin(admin.modeladmin):     inlines = [         reviewinline,     ] 

the documentation has example of exact scenario, except multiple authors instead of multiple reviews:


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -