开发者

Django custom method won't show up

开发者 https://www.devze.com 2023-02-27 05:00 出处:网络
I have two custom methods for a model manager in Django.One of them works.I recently added another and Django (and python) act like it doesn\'t exist.Here\'s the relevant part of the model:

I have two custom methods for a model manager in Django. One of them works. I recently added another and Django (and python) act like it doesn't exist. Here's the relevant part of the model:

class FigureServerManager(models.Manager):
    #This method takes as input a user and grabs a figure that is not marked complete for which that user has not already submitted a result
    def serve_to_user(self,user):
    not_complete=super(FigureServerManager, self).get_query_set().filter(complete=0)
    for Figure in not_complete:
        checkifresult=User.objects.get(pk=user).result_set.all().filter(figure=Figure.id)
    if not checkifresult:
            return Figure

    #This is a copy of the above method that I want to change to do something else, but I can't even get it to show up yet
    def serve_training_task(self, user):
        with_correct_ans=super(FigureServerManager, self).get_query_set().filter(complete=0)
        for Figure in with_correct_ans:
            checkifresult=User.objects.get(pk=user).result_set.all().filter(figure=Figure.id)
开发者_开发知识库        if not checkifresult:
                return Figure

class Figure(models.Model):
    doi=models.CharField(max_length=20)
    url=models.CharField(max_length=200)
    image=models.ImageField(upload_to='classify')
    complete=models.BooleanField()
    #include the default manager    
    objects=models.Manager()
    #add the extra one for serving figures
    serve_objects=FigureServerManager()

I get an error on the website (running the Django development server) like this:

'FigureServerManager' object has no attribute 'serve_training_task'

and if I run dir(FigureServerManager) in python the serve_training_task method does not appear but the serve_to_user method does appear. Why doesn't serve_training_task work?


Python Language Reference, §2.1.8: "Indentation"

0

精彩评论

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