I have a question on creating my url. I have a model like this –
class Conversation(models.Model):
created_on = models.DateTimeField(auto_now_add=True)
subject = models.TextField()
started_by = models.ForeignKey(User,related_name='creator')
target = models.ForeignKey(User,related_name='receiver')
class UnreadItems(models.Model):
unread = models.BooleanField()
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
user = models.ForeignKey(User,null=True)
content_object = generic.GenericForeignKey('content_type','object_id')
I require a view whereby i return all unread conversations of the current logged-in user (i have around 3 classes of users in my application). For my url, I can probably have foo.com/conversation/unread?user_id=234fsg88j or I can have simply use foo.com/conversation/unread/ and use request.user to filter the user’s conversation.
Is the latter a sounder approach and/or what is the disadvantage in using it?
Admittedly, this is a pretty subjective question, But I tend to put data pertaining to a particular User at the front of the url. Since conversations are a resource belonging to the user, that would follow the user. Unread is really a predicate that filters out some of the data, much like a page range, or “starred” items, so that would end up in a query parameter. Finally, I like my parameters to be easy to construct in javascript, so My url for this would look like
If the conversations should never be visible except to the user that owns them, then it would go on a resource that is per-user, something like