如何在管理站点

时间:2015-09-08 04:14:34

标签: python django django-models django-admin

django 1.8

models.py

class hotel(models.Model):
    hotel_name = models.CharField(max_length=200)

class items(models.Model):
    items_id = models.ForeignKey("hotel")

class Sell(models.Model):
    orderform = models.ForeignKey("Orderform")
    sell_id = models.ForeignKey("sell", limit_choices_to={'hotel_id': items.items_id})
    sell_count = models.IntegerField(default=1)

admin.py

class itemsInline(admin.TabularInline):
    model = Sell
    extra = 1

class itemsAdmin(admin.ModelAdmin):
    inlines= [itemsInline]

我想获取项目模型items_id字段

实施例

<hotel:1> items_set have [<sell:banana>,<sell:apple>]
<hotel:2> items_set have [<sell:grapes>,<sell:starfruit>]

如果打开url / admin / myapp / items / 1 /

可以将items_id设置为1

返回结果[<sell:banana>,<sell:apple>]

0 个答案:

没有答案