简体   繁体   中英

Django custom method won't show up

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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