Reputation: 657
I use mongodb as the django nonrel database to build a blog site. The basic models for the blog site are:
class Post:
comments = ListField(EmbeddedModelField('Comment'))
....(omitted here)
class Comment:
created = models.DateTimeField(auto_now_add=True)
author = models.CharField(max_length=35)
email = models.EmailField(max_length=64)
text = models.TextField()
ip_addr = models.IPAddressField()
I found that when I created a comment and append it to the listfield of a post, the comment will not have an objectid because it's embedded. Thus, when I want to delete a comment, I have trouble to let the database know which comment I want to delete. Is it possible that I pass the comment from the template to views without the url function in urls.py?
Upvotes: 0
Views: 109
Reputation: 20339
You can rewrite the model as
class Post:
comments = ListField(models.ForeignKey('Comment'))
....(omitted here)
class Comment:
created = models.DateTimeField(auto_now_add=True)
author = models.CharField(max_length=35)
email = models.EmailField(max_length=64)
text = models.TextField()
ip_addr = models.IPAddressField()
Upvotes: 0