My example is a list of movies and awards they could have won (ie.
"Oscar, Best Picture").
So I create the Award object:
class Award(meta.Model):
description = meta.CharField(maxlength=100)
def __repr__(self):
return self.description
class META:
admin = meta.Admin()
Then I create the Movie object:
class Movie(meta.Model):
year = meta.SmallIntegerField()
title = meta.CharField(maxlength=100)
period = meta.CharField(maxlength=1, choices=PERIOD_CHOICES)
plot = meta.TextField()
awards = meta.ManyToManyField(Award)
def __repr__(self):
return self.title
def short_plot(self):
output = self.plot
if len(output) > 100:
output = self.plot[:100] + "..."
return output
short_plot.short_description = "Plot extract"
class META:
ordering = ('-year', 'title')
admin = meta.Admin(
list_display = ("title", "year", "period", "short_plot"),
)
The only catch is that in the Admin piece, I am required to select at
least one award for any movie I enter, however the vast majority of
movies have 0 awards. What's the best way to approach this?
By the way, i'm newish to Python and Django. I'm employed as a C# &
Java/Struts guy. I'm starting to wish my "native" platforms had
Django's feature set.