How do you retrieve a specific object from a class using a ForeignKey?
I created a class called TryoutJersey with three objects.
class TryoutJersey(models.Model):
jerseyColour = models.CharField(max_length=50, blank=True, null=True)
jerseyNumber = models.IntegerField(unique=True, blank=True, null=True)
jerseyDescription = models.CharField(max_length=50, blank=True, null=True)
def __str__(self):
return self.jerseyColour
and I want to assign a jersey to a player in my player class using a ForeignKey.
tryoutJerseyNumber = models.ForeignKey(TryoutJersey, blank=True, null=True, on_delete=models.CASCADE, related_name='JerseyNumber')
How would I do this? The jersey is a single item with a color, a number and a description. Should I have some unique identifier other than those three items to tie to the player and return that? What would that be? Wondering what others would commonly use. Like a part number I suppose. Is there a number generator that people use? I’m stuck here. I want the TryoutJersey class for the admin section so I can add jerseys. They tend to change from season to season. Not sure what to do here.
This is really more if a database question than a Django question I think.