My problem is that I specify the get_next_by_FOO method, but the link does not work correctly.
#models.py
class Project(models.Model):
user = ForeignKey(settings.AUTH_USER_MODEL, on_delete=CASCADE, db_index=True)
name = CharField(max_length=150, db_index=True)
cover = models.ImageField( upload_to="project_photos/", null=True, blank=True
)
site = URLField( max_length=200)
description = TextField()
note = CharField( max_length=150)
created_at = DateTimeField(auto_now_add=True)
def next(self):
return self.get_next_by_created_at()
def pre(self):
return self.get_previous_by_created_at()
#html
<a href="">Next project</a>
<a href="">Previous project</a>
And it gives out the following link:
http://localhost:8000/projects/8/%D0%9D%D0%BE%D0%B2%D0%B0%D1%8F%20%D1%80%D1%83%D0%B1%D1%80%D0%B8%D0%BA%D0%B0
The id of the model does not change, and the name of the next or previous model instance is appended to the end of the link
Aucun commentaire:
Enregistrer un commentaire