I'm creating an API using the django rest framework want to store an array of pictures inside my user model. For each picture I should have an URL and boolean flag indicating whether it is the display picture or not. There should be atleast 2 and maximum 6 pictures. One and only one of those pictures should have the display_picture_flag set as true. What would be a good way to model this.
My approach (Might not be best) -
- I'm thinking of creating another model class with user id from user class as the foreign key. It will have an URL field and a boolean field aswell. My doubts with this are,
- How will I validate number of objects as lying in [2,6]. Validating that only one flag is true.
- Creating [2,6] objects at the same time (single Create API call).
- Using JSON field. probably store as dictionary with URL mapped to flag.
- Again, confused with validations.
Please suggest better approaches, or expand upon my approaches. Thanks!