lundi 11 juillet 2016

Having a model to relate to several different models


I have a simple notification model:

class Notification(models.Model):
    user = models.ForeignKey(User)
    sender = models.ForeignKey(User)
    model = '''What to put here?'''
    comment = models.CharField(max_length=200)
    created = models.DateTimeField(auto_now=False,auto_now_add=True)

I need the notification to relate to several different models, for example; posts, user follows, etc

Is there anyway in django you can relate to several models instead of creating a notification model for each one?

I want to avoid models like this: PostLikeNotification, UserFollowNotification, etc.

So does django have this functionality? I couldn't find it anywhere in the docs.


Aucun commentaire:

Enregistrer un commentaire