So I know in a relational database with a many to many field it creates a relationship object that holds the keys for both things its tied to.
I currently have models like this
class ConfirmEmail(models.Model):
owner = models.CharField(max_length = 100)
emails = models.ManyToManyField(Sdm)
report = models.ForeignKey(Report)
def url(self):
return "/admin/phone/confirmemail/" + str(self.id) + "/change/"
def __str__(self):
return str(self.owner) + ": " + str(self.report)
class PhoneConfirmemailEmails(models.Model):
confirmemail_id = models.IntegerField()
sdm_id = models.IntegerField()
distance = models.FloatField(blank = True, null = True)
class Meta:
managed = True
db_table = 'phone_confirmemail_emails'
unique_together = (('confirmemail_id', 'sdm_id'),)
ordering = ('distance',)
The PhoneConfirmemailEmails model is the relational object that ties the confirmation email models and its list of SDM objects. (Seen in its Many to Many relationship). (I know im now using the through keyword but trust me this was the model auto created by django so that works) You can see that I have added a distance variable. What I would like is on the admin page if the ManyToManyField was organized by that distance variable. From largest to smallest distance.
Is there any way to do this?
Thank you