I am working on a ride share application. I need help on designing the models for private messages.
I have designed the below models, its look like complex in querying them in views. can you guys help me in design a better and easy one!
class Ride(models.Model):
type = models.BooleanField(default=False)
add_source = models.ForeignKey(Address, related_name='source')
add_destination = models.ForeignKey(Address, related_name='destination')
ride_startDateTime = models.DateTimeField(default= datetime.datetime.now, blank=True)
ride_startPref = models.CharField(max_length=10, choices=CHOICES, default='None')
class Conversation(models.Model):
ride_id = models.ForeignKey(Ride)
class Messages(models.Model):
conversation_id = models.ForeignKey(Conversation)
ride_id = models.ForeignKey(Ride)
sender_id = models.ForeignKey(User, related_name='sender')
receiver_id = models.ForeignKey(User, related_name='receiver')
Content = models.TextField(max_length=1000,blank=True)
timestamp = models.DateTimeField(default= datetime.datetime.now, blank=True)
status = models.CharField(max_length=10,blank=True)
User model is django inbuilt. Please consider the following use cases:
1) A Conversation has to integrate with Ride, For Ex: User X is a owner of ride 3, User Y can contact X for this ride(3), then the new conversation id(77) will be generated. After that whatever messages sent between them should be under the same conversation id(77). If another user Z is trying to contact the user X for the same ride 3, then a new conversation ID(33) has to generated.
2) If the user X having another ride called 4, then if user Y contact the User X through the other ride means, it has to generate new conversation id(99) and all the messages sent between them on the ride should come under the same conversation id(99).