简体   繁体   English

在Django的管理面板中添加逻辑

[英]Add logic in admin panel in Django

I have two models, the second model is FK from my first model like this: 我有两个模型,第二个模型是我的第一个模型中的FK ,如下所示:

class Model0(models.Model):
    work = models.FloatField(blank=True, null = True)

class Model1(models.Model):
    class Meta:
    unique_together = (('lat', 'lng'),)
    lng = models.FloatField(blank=True, null=True)
    lat = models.FloatField(blank=True, null=True)

class Model2(models.Model):
    idWork    = models.ForeignKey('Model0', on_delete=models.CASCADE)
    idSTFolio = models.OneToOneField('Model1', on_delete=models.CASCADE)

I use admin panel to add my data, I need that when I add a second (Model0, Model1) with others values to Model1, in my Model2 this association was created automatically like this: 我使用管理面板添加我的数据,当我向Model1添加第二个(Model0,Model1)以及其他值时,我需要在Model2中自动创建该关联,如下所示:

for example: 例如:

Model2 : (Model0, Model1) 型号2 :(型号0,型号1)

Id 1 : (1.5, (2.5, 3.0)) , 1.5 is 'Work' from Model0 and (2.5, 3.0) lat and lng in Model1 Id 1 : (1.5, (2.5, 3.0)) 2.5,3.0 Id 1 : (1.5, (2.5, 3.0)) ,1.5是Model0中的'Work'和Model1中的(2.5,3.0)lat和lng

I need something like this...in this moment I create other Model1 with these values (2.5, 4.0), so like lat: 2.5 has already been added in Model2 I need that in my Model2 add other row like this automatically : 我需要这样的东西...此刻,我用这些值(2.5、4.0)创建其他Model1,所以像lat: 2.5在Model2中已经添加了lat: 2.5 ,我需要在Model2中自动添加其他这样的行:

Id 1 : (1.5, (2.5, 3.0)) Id 2 : (1.5, (2.5, 4.0))

Any idea if it is possible to modify the admin panel for what I need? 任何想法是否可以根据我的需要修改管理面板? In this moment I must add this association in my Model2 page in admin panel, but It not is my idea. 此时,我必须在管理面板的“ Model2”页面中添加此关联,但这不是我的想法。

I just googled for multi-level inlines and found django-nested-inline package . 我只是谷inlines搜索多级内inlines ,发现django-nested-inline包

It seems promising to me for your purpose. 对您来说,对我来说似乎很有前途。 I have found this in many stackoverflow answers as well: 我也在很多stackoverflow答案中找到了这一点:

I have never tried this package but I think, this will work for you. 我从未尝试过此软件包,但我认为,这对您有用。 Please let me know if it works for you. 请让我知道它是否适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM