如何将DEBUG应用于django管理表单字段? [英] How to apply DEBUG to the django admin forms fields?

查看:142
本文介绍了如何将DEBUG应用于django管理表单字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用模型中的字段,其中字段的值取决于表单中的上一个字段(通过django管理员)的所选选项,通过该字段我使用 django-smart-choices



我会分享此视频,以更好地了解我的问题或情况及原因关于请求使用DEBUG或净化方式与我在这种情况下工作的字段相关。




  • 父母视频中的 Segmento afectado 让我选择多个选项


  • 子字段视频中的Movimiento 详细列出受影响的细分(在父字段中选择)可以执行的动作




我的情况


    视频中详细说明了当我在父字段中只选择一个受影响的段时,动作选项会部署在子字段中,而Django Server的日志控制台则显示为状态代码HTTP / 1.1 200 GET 操作,表明可以获取并部署成功对应于在父域中选择的受影响的段


  1. 但是,当我在父域中选择多个受影响的段时(如果我在转发中选择两个或多个段),立即我的django服务器在控制台显示我的状态代码HTTP / 1.1 404 未找到黄色),因为不执行用户选择的第二选择或第二受影响的段,并且由于这个原因也不会在子字段中部署或出现与第二受影响段相关联的运动可以执行


我不知道h要解决这种情况,由于这种形式是父母( Segmento Afectado )和孩子( Movimiento )我有一个名为 AffectedSegment 的模型,另一个名为<$ c $的模型,

c>运动并通过 ChainedManyToManyField 的功能 django-smart-choices 是如何获取在子字段中部署的值符合父字段中的选择的方式。



我的模型和这个行为的链接是:

  class AffectedSegment 
SEGMENTO_ESCAPULA ='ESCAPULA'
SEGMENTO_HOMBRO ='HOMBRO'
SEGMENTO_CODO ='CODO'
SEGMENTO_ANTEBRAZO ='ANTEBRAZO'
SEGMENTO_CARPO_MUNECA ='CARPO_MUNECA'
SEGMENTO_MANO ='MANO'
SEGMENTO_CHOICES =(
(SEGMENTO_ESCAPULA,u'Escápula'),
(SEGMENTO_HOMBRO,u'Hombro'),
(SEGMENTO_CODO,u'Codo'),
(SEGMENTO_ANTEBRAZO,u'Antebrazo'),
(SEGMENTO_CARPO_MUNECA,u'Carpo /Muñeca'),
(SEGMENTO_MANO,u'Mano'),

affected_segment = models.CharField(max_length = 12,choices = SEGMENTO_CHOICES,blank = False,verbose_name ='Segmento afectado')

class Meta:
verbose_name ='Segmentos corporale'

def __str __(self):
return%s%self.affected_segment

class运动(models.Model):
type = models.CharField(max_length = 255,verbose_name ='Tipo de movimiento')
corporal_segment_associated = models.ManyToManyField(AffectedSegment,blank = False,verbose_name ='Segmento corporal asociado')

class Meta:
verbose_name ='Movimiento'

def __str __(self):
返回%s%self.type

而且,通过父母领域的选择,孩子领域的动作符合的方式是这样做:

  class RehabilitationSession(models.Model):

affected_segment = models.ManyToManyField(AffectedSegment,verbose_name ='Segmento afectado')
movement = ChainedManyToManyField(
运动, #Modelo encadenado
chained_field ='affected_segment',
chained_model_field ='corporal_segment_associated',
verbose_name ='Movimiento'


class Meta:
verbose_name ='Sesiones deRehabilitación'

def __str __(self):
return%s%self.affected_segment

我不知道如何解决这种情况。
我可以有另外一个选择?
JS,一些框架forntend?
另一个django应用程序?



任何支持,方向,将高度赞赏



: D

解决方案

只需简单地查看您的视频和django-smart-select应用程序的代码,我可以看到这个应用程序不是要做你正在尝试的。



当您只选择一个选项时,您的网址结尾如下所示:

 code>../康复行为/运动/ 4 /

但是当你选择两个选项,您的网址如下所示:

 ../康复活动/动作/ 4,5 /

然后你会得到404错误。



您的错误原因在于应用程序django-smart-select没有适当的url模式来处理4,5块。为了使其工作,它需要接受逗号分隔的整数,然后在应用程序中实现某种解析器,以便在多个条件下过滤结果。



我无法给你完整的答案,但我可以告诉你,你有几个选择:


  1. 如果您有技能,您可以尝试扩展上述应用程序,并自行实现解析器和URL格式。


  2. 您可以在管理员类中执行相同的操作,方法是根据上述字段的选择覆盖字段的查询,但不进行jQuery修改,则不会进行实时更改。


  3. 您可以尝试其他一些应用程序,但是我无法保证为您的问题找到合适的解决方案。



I am working with fields in a model in which the value of a field depend of a selected option in a previous field in a form (for the moment via django administrator), by which I am using django-smart-selects

I would share this video for a better understanding about of my question or situation and the reason about of ask the way of apply DEBUG or depuration in relation with the fields which I am working in this scenario.

  • The parent field Segmento afectado in the video let me select multiple choices

  • The child field Movimiento in the video, detail the movements that a affected segment (selected in the parent field) can perform

My situation about it

  1. In the video is detailed of a way clear that when I select only a affected segment in the parent field, the options of movements are deployed in the child field, and my log console of Django Server appear the status code HTTP/1.1 200 with the GET operation, indicating to me that was possible get and deploy successfully the movements that correspond to the affected segment selected in the parent field

  2. But, when I select more than one affected segment in the parent field (If I select two or more segments in forward), inmediately my django server at the console show me the status code HTTP/1.1 404 (Not Found in yellow color), because not perform the second selection or the second affected segment that the user select, and due to this reason also don't deploy or appear in the child field the movements associated that these second affected segment can perform

I don't know how to address this situation, due to this form in which are the parent (Segmento Afectado) and child (Movimiento) fields are represented inside the django administrator.

I have a model named AffectedSegment and another model named Movement and through of functionality of ChainedManyToManyField of django-smart-selects is the way in how to I get the values deployed in the child field accord to the selection in the parent field.

My models and the chaining of values for this behavior are:

class AffectedSegment(models.Model):
    SEGMENTO_ESCAPULA = 'ESCAPULA'
    SEGMENTO_HOMBRO = 'HOMBRO'
    SEGMENTO_CODO = 'CODO'
    SEGMENTO_ANTEBRAZO = 'ANTEBRAZO'
    SEGMENTO_CARPO_MUNECA = 'CARPO_MUNECA'
    SEGMENTO_MANO = 'MANO'
    SEGMENTO_CHOICES = (
        (SEGMENTO_ESCAPULA, u'Escápula'),
        (SEGMENTO_HOMBRO, u'Hombro'),
        (SEGMENTO_CODO, u'Codo'),
        (SEGMENTO_ANTEBRAZO, u'Antebrazo'),
        (SEGMENTO_CARPO_MUNECA, u'Carpo/Muñeca'),
        (SEGMENTO_MANO, u'Mano'),
    )
    affected_segment = models.CharField(max_length=12, choices=SEGMENTO_CHOICES, blank=False, verbose_name='Segmento afectado')

    class Meta:
        verbose_name = 'Segmentos corporale'

    def __str__(self):
        return "%s" % self.affected_segment

class Movement(models.Model):
    type = models.CharField(max_length=255,verbose_name='Tipo de movimiento')
    corporal_segment_associated = models.ManyToManyField(AffectedSegment, blank=False, verbose_name='Segmento corporal asociado')

    class Meta:
        verbose_name = 'Movimiento'

    def __str__(self):
        return "%s" % self.type

And the way in which or I get that appear the movements in the child field accord to the selection on the parent field is perform of this way:

class RehabilitationSession(models.Model):

    affected_segment = models.ManyToManyField(AffectedSegment,verbose_name='Segmento afectado')
    movement = ChainedManyToManyField(
        Movement, #Modelo encadenado
        chained_field = 'affected_segment',
        chained_model_field = 'corporal_segment_associated',
        verbose_name='Movimiento'
    )

    class Meta:
        verbose_name = 'Sesiones de Rehabilitación'

    def __str__(self):
        return "%s" % self.affected_segment

I don't know how to can I address this situation. What another alternatives can I have? JS, some framework forntend? Another django app?

Any support, orientation about it, will be highly appreciated

:D

解决方案

Just by briefly looking to your video and the code of "django-smart-select" application, I can see that this application was not meant to do what you are trying.

When you select only one option, the ending of your url looks like this:

"../RehabilitationSession/movement/4/"

But when you select two options, your url looks like this:

"../RehabilitationSession/movement/4,5/" 

and then you get the 404 error.

Reason for you error lies in the fact that the application "django-smart-select" don't have an appropriate url pattern to deal with "4,5" block. For this to work, it would need to accept comma-separated integers and then have some kind of parser implemented in the app to filter your results by multiple conditions.

I cannot give you the complete answer, but I can tell you that you have few options:

  1. If you have the skill, you can try and extend the mentioned app and implement the parser and url patterns yourself.

  2. You can do the same thing in your admin class by overriding the query of your field based on the selection of the above field, but without jQuery tinkering, it wont have real-time changes.

  3. You can try some other application, but I cannot guarantee that you will find a suitable solution for your problem.

这篇关于如何将DEBUG应用于django管理表单字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆