[Answer]-Django clickable field for href

1đź‘Ť

It’s a bit hard to understand your question, but I’m guessing that, rather than use choices you want a related model, like so:

class ReadStatus(models.Model):
    status=models.CharField(max_length=20)

class Result(models.Model):
    read_status=models.ForeignKey(
             ReadStatus, null=False,
             default=lambda: ReadStatus.objects.get(status="Unread"))
    creation_time=models.DateTimeField(auto_now_add=True, null=False)

A few notes:

  1. Each instance of the model (Result) for example, references a single row – hence my use of the singular “Result” rather than Results (obviously, you can do whatever you want, but understanding the reasoning sometimes helps.)
  2. The default is set using a query – which ASSUMES that there is a single row in ReadStatus that has status of “Unread”. If that’s not the case, then you will have issues using the default for the Result model.
👤chander

Leave a comment