开发者

django: why it shows only one TabularInline object instance?

开发者 https://www.devze.com 2023-03-17 09:29 出处:网络
I\'ve two classes: class Post(models.Model): and class Image(models.Model): url = models.CharField(max_length=400)

I've two classes:

class Post(models.Model):

and

class Image(models.Model):
    url = models.CharField(max_length=400)
    post = models.ForeignKey("Post", unique=True, related_name='posts')

the problem is that in admin site I see only ONE Tabular/StackedIn开发者_JAVA技巧line object Image for a Post.

Here is my admin.py

class ImageInline(admin.TabularInline):
    model = Image
    fk_name = 'post'
    extra = 5

class PostAdmin(admin.ModelAdmin):
    inlines = [
        ImageInline,
    ]
    list_display = ('name', )
    search_fields = ['name',]
    ...

admin.site.register(Post, PostAdmin)

...where I'm worng ? According to extra parameter in TabularInline I should have 3 images to add to Post...but it only shows up 1.

Thanks


You're only allowing one image per post, because you're specifying unique=True on the ForeignKey.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号