Django class overrides fails System check

别说谁变了你拦得住时间么 提交于 2019-12-07 04:15:23

问题


I am trying to upgrade from Django 1.7.1 to 1.8 on my dev env. I seem to be having an issue with one of my models, I think a core file got upgraded and its messing with my model. I cant seem to figure out what's causing it to die.

This is the only error I get when I attempt to run a manage.py test

CommandError: System check identified some issues:

ERRORS:
graphite_alerts.CheckResults: (models.E020) The 'CheckResults.check()' class method is currently   overridden by <django.db.models.fields.related.ReverseSingleRelatedObjectDescriptor object at 0x3a76310>.

I tried changing the class name and looked around my model and cant seem to find anything that would be causing an override error

This is the class:

class CheckResults(models.Model):

    WARN = 'warn'
    ERROR = 'error'
    OK = 'ok'
    DOWN = 'down'
    STATUS_CHOICES = (
        (WARN, 'Warn'),
        (ERROR, 'Error'),
        (OK, 'OK'),
        (DOWN, 'Down'),
    )

    target = models.CharField(max_length=1000)
    additional_graph_target = models.CharField(max_length=1000, blank=True)
    value = models.DecimalField(max_digits=9, decimal_places=2)
    timestamp = models.DateTimeField(db_index=True)
    status = models.CharField(max_length=6, choices=STATUS_CHOICES, default='ok')
    check = models.ForeignKey(Check, related_name='results')
    tags = TaggableManager()

    def __unicode__(self):
        return self.target

    @models.permalink
    def get_absolute_url(self):
        return ('graphite-check-result-list-view', (), {'pk': self.check.pk, 'target': self.target})

    def generate_graphite_image_url(self):
        params = { }
        params['target'] = []
        params['target'].append(self.target)
        params['target'].append('threshold(' + str(self.check.warn) + ',"Warn","yellow")')
        params['target'].append('threshold(' + str(self.check.error) + ',"Error","red")')
        params['from'] = '-7days'
        params['width'] = '900'
        params['minorGridLineColor'] = 'C0C0C0'
        params['majorGridLineColor'] = 'C0C0C0'
        params['bgcolor'] = '333333'
        request = requests.get(self.check.GRAPHITE_URL+self.check.RENDER_PAGE,params=params)
        return urllib2.unquote(request.url.decode('UTF-8'))

    def generate_additional_graphite_image_url(self):
        params = { }
        params['target'] = []
        params['target'].append(self.additional_graph_target)
        params['target'].append('threshold(' + str(self.check.warn) + ',"Warn","yellow")')
        params['target'].append('threshold(' + str(self.check.error) + ',"Error","red")')
        params['from'] = '-7days'
        params['width'] = '900'
        params['minorGridLineColor'] = 'C0C0C0'
        params['majorGridLineColor'] = 'C0C0C0'
        params['bgcolor'] = '333333'
        request = requests.get(self.check.GRAPHITE_URL+self.check.RENDER_PAGE,params=params)
        return urllib2.unquote(request.url.decode('UTF-8'))

    class Meta:
        ordering = ("timestamp",)
        unique_together = (("target", "timestamp"),)

回答1:


I ran into the same problem while updating a project from 1.6 to 1.8.

The issue seems to stem from the check field that your model has.
It conflicts with the Model.check() method, which is called during Django's system checks to help you identify errors in model definition.

You'll have to rename the field.



来源:https://stackoverflow.com/questions/27607988/django-class-overrides-fails-system-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!