Having a such model, I want to make sure only one Photo for each album to have a cover. This will be used as InlineModelAdmin to the Album model.
class Photo(models.Model):
is_cover = models.BooleanField( default=False)
album = models.ForeignKey('Album')
image = ImageField(upload_to='uploads')
How can this be achieved ?
Which photo is on the cover of the album should be a property of the album, not the Photo.
Instead of using a boolean property in your Photos, use a reference to a Photo in your Album.
Answer to Comment: Assuming that 'inline model' means what I assume it to be in my comment, you will probably have to provide your own add form template. Using it, you can still provide the option boxes (instead of check boxes) and then set up the Album
correctly in the code that processes the contents of the submitted form.
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