I have a class named Product that includes multiple Image objects. In my admin, I have Product include Images as a tabular inline element.
Here's the dilemma, each image has a featured boolean field and I would like to make a checkbox that can only be chec开发者_StackOverflowked once across multiple tuples. In essence, no two images can be featured at the same time.
featured = models.Boolean(_('Featured'))
How can I code this?
Thank you, Mark
Without knowing the specifics of your project, it might make more sense to put the featured
field (say, a ForeignKeyField) in your Product model, rather than in the Image model. In this way, you'd ensure the uniqueness of the field without any extra work.
If you put it in your Image class instead, things would start to get very complicated if, for example, multiple Products share the same Image - how would you know which featured Image went with which Product?
精彩评论