2

I have the following Django model:

from mongoengine import *
from datetime import datetime

class Company(Document):

    name = StringField(max_length=500)



class Feedback(Document):

    text = StringField(max_length=500)
    is_approved = BooleanField(default=False)
    date = DateTimeField(default=datetime.now())

I want to add a manytomany field of Feedback in Company

Thanks in advance.

Aslam Khan
  • 400
  • 5
  • 20
  • @Anto this is not a Django model, it's a mongoengine Document. Django's documentation will be of no help. – Spc_555 Aug 29 '14 at 13:04

1 Answers1

5

This is not a Django model, but a mongoengine Document. It does not have ManyToManyField. Instead you should probably add a ReferenceField inside a ListField to your Company class, like this:

class Company(Document):
    name = StringField(max_length=500)
    feedbacks = ListField(ReferenceField(Feedback))

class Feedback(Document):
    text = StringField(max_length=500)
    is_approved = BooleanField(default=False)
    date = DateTimeField(default=datetime.now())

Source: http://docs.mongoengine.org/guide/defining-documents.html#one-to-many-with-listfields

Spc_555
  • 4,081
  • 2
  • 27
  • 34
  • I have one more doubt in this topic. ***i cant add feedback object in Company.feedbacks.*** please help me. – Aslam Khan Aug 29 '14 at 13:52
  • Please check out the link I gave as source. I believe it has pretty concise examples. – Spc_555 Aug 29 '14 at 16:57
  • @VasilyAlexeev Is there has any errors when I am saving the Company object without a Feedback Instance How can I add required = False inside feedbacks = ListField(ReferenceField(Feedback)). – Varnan K Aug 30 '14 at 11:10
  • @VarnanK I think changing it like this should help: `feedbacks = ListField(ReferenceField(Feedback), default=list)` – Spc_555 Aug 30 '14 at 23:30