# Here's some models class Order(models.Model): shipping_method = models.CharField(max_length=20) class Delivery(models.Model): order = models.ForeignKey('Order', null=True, blank=True) # If this is NULL, then the shipping method is as billed, in order.shipping_method # If this is not NULL, then this is the shipping method that was actually used. shipping_method_override = models.CharField(max_length=20, null=True) def get_method_name(self): if self.shipping_method_override: return self.shipping_method_override else: return self.order.shipping_method # Now let's say this is in a view # How do I get a list of deliveries sorted by the actual method used? deliveries_sorted_by_actual_method = Delivery.objects.order_by(?)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question