I have two relationships:
class Contact(models.Model):
first_name =models.CharField(max_length=30)
class Activity(models.Model):
action =models.CharField(max_length=200)
whom =models.ForeignKey("Contact", null=True, blank=True)
With
contacts=Contact.objects.get(slug=contactslug)
I can call the specific Contant from my url request
And additionally
c = contacts.activity_set.all
lets me call all the activities.
How can I call the activities but in reverse order since .order_by()
or reverse()
doesn't seem to work.
This will probably work
reversed(contacts.activity_set.all())
But, you should do this:
class Activity(models.Model):
action =models.CharField(max_length=200)
whom =models.ForeignKey("Contact", null=True, blank=True)
class Meta:
ordering = ['action']
or ['-action']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With